[Vue]数据双向绑定v-model

发布时间 2023-10-17 14:45:31作者: 夕苜19

v-model: 只能用于表单类元素(输入类元素,有value值)
v-model:value 可以简写为 v-model

以下代码是错误的:
<a v-model:href="url">hello</h2>     (v-model 只能用于表单元素) 

 

<body>
    <div id="root">
        <!-- 普通写法 -->
        单向数据绑定:<input type="text" name="" id="" v-bind:value="url"><br />
        双向数据绑定:<input type="text" name="" id="" v-model:value="style"><br />
        <!-- 简写 -->
        单向数据绑定:<input type="text" name="" id="" :value="url"><br />
        双向数据绑定:<input type="text" name="" id="" v-model="style"><br />
    </div>
</body>
<script>
    const vm = new Vue({
        el: '#root',
        data: {
            name: '模板',
            url: "https://www.bilibili.com",
            style: "hello"
        }
    })
</script>