数据双向绑定

# input :text,password,select...
# text文本类型的双向数据绑定 
-使用 :value='变量'   单向数据绑定,页面变化,变量不会跟着变---》一般不用
-使用 v-model='变量'  双向数据绑定,页面变化,变量变化都会相互影响

使用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="vue.js"></script>
</head>
<body>
<div id="app">
    <h1>v-model 只针对于input</h1>
    <input type="text" v-model="v">
    <button @click="clickEvent">按钮</button>
</div>
</body>
<script>
    const app = Vue.createApp({
        data() {
            return {
                v:'sb'
            }
        },
        methods: {
            clickEvent(){
                alert(this.v)
            }
        }
    })
    app.mount("#app")
</script>
</html>
posted @ 2022-10-19 14:26  Sherwin_szw  阅读(16)  评论(0编辑  收藏  举报