<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="../../js_lib/vue-2.3.0.js"></script>
<!--<script src="../../js_lib/vue-2.3.0.min.js"></script>-->
<script>
Vue.component('child_1', {
template: '<div>\
<p><input type="text" v-model="namex"></p>\
</div>',
props: ['name'],
data:function(){
return {
namex: this.name
};
},
watch: {
// 當本身 name 有變動
// 通知 parent 更新自身數據
namex: function(){
this.$emit('update:name', this.namex);
}
}
});
</script>
</head>
<body>
<div id="app">
<div>
<input type="text" v-model="name">
</div>
<hr>
<child_1 :name="name" @update:name="getName"></child_1>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
name: 'a.......'
},
methods: {
getName: function (value) {
// debugger;
this.name = value;
}
}
});
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="../../js_lib/vue-2.3.0.js"></script>
<!--<script src="../../js_lib/vue-2.3.0.min.js"></script>-->
<script>
Vue.component('child_1', {
template: '<div>\
<p><input type="text" v-model="namex"></p>\
</div>',
props: ['name'],
data:function(){
return {
namex: this.name
};
},
watch: {
// 當本身 name 有變動
// 通知 parent 更新自身數據
namex: function(){
this.$emit('update:name', this.namex);
}
}
});
</script>
</head>
<body>
<div id="app">
<div>
<input type="text" v-model="name">
</div>
<hr>
<child_1 :name="name" @update:name="getName"></child_1>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
name: 'a.......'
},
methods: {
getName: function (value) {
// debugger;
this.name = value;
}
}
});
</script>
</body>
</html>