vue

安装

  1. npm 安装 首先使用npm init新建一个node js项目
    之后输入一些项目信息即可
    image
  2. 根据文档安装vue
    image
  3. 根据文档引入vue
    image
    image

常用指令

首先新建一个vue实例

和vue2 语法不同 变成根据对象创建实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script src="node_modules/vue/dist/vue.global.prod.js"></script>
</head>
<body>
    <div id="app">

    </div>
</body>

    <script>
        const Counter = {
            data() {
                return {
                }
            }
        }

        Vue.createApp(Counter).mount('#app');
    </script>

</html>

双向绑定和单项绑定

双向绑定指 标签与数据相联系 两者修改都会受到影响
单项绑定是执元素和数据绑定 只有数据改变标签才会变 标签改变数据不会变

v-html

将元素按html输出

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script src="node_modules/vue/dist/vue.global.prod.js"></script>
</head>
<body>
    <div id="app">
        <span v-html="h">

        </span>
    </div>
</body>

    <script>
        const Counter = {
            data() {
                return {
                    h: '<h1>Hello world</h1>'   
                }
            }
        }

        Vue.createApp(Counter).mount('#app');
    </script>

</html>

v-text

按文本输出

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script src="node_modules/vue/dist/vue.global.prod.js"></script>
</head>
<body>
    <div id="app">
        <span v-text="h">

        </span>
    </div>
</body>

    <script>
        const Counter = {
            data() {
                return {
                    h: '<h1>Hello world</h1>'   
                }
            }
        }

        Vue.createApp(Counter).mount('#app');
    </script>

</html>

v-bind

将元素属性绑定

posted @ 2021-10-26 17:50  RainbowMagic  阅读(31)  评论(0)    收藏  举报