使用vue的sync修饰符进行子父组件的数据绑定
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                使用vue的sync修饰符进行子父组件的数据绑定
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                官方文檔
父組件代碼
<template><div><input type="button" value="我是父組件的按鈕" @click="show" /><!-- 在需要子組件修改的數(shù)據(jù)后加上.sync即可 --><child :isShow.sync='isShow' v-show="isShow" /></div> </template> <script> import child from './child' export default {components:{child},data () {return {isShow: false}},methods: {show() {this.isShow = true},} } </script>子組件代碼塊
<template><div>我是一個子組件<button @click="childisShow">點我隱身</button></div> </template> <script> export default {methods: {childisShow() {//當子組件需要修改父組件的值時,需要顯示觸發(fā)更新事件// this.$emit('update:XXXX','內(nèi)容')this.$emit('update:isShow',false)}} } </script>總結(jié)
以上是生活随笔為你收集整理的使用vue的sync修饰符进行子父组件的数据绑定的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 电子商务网站源码HTML5+CSS3+J
 - 下一篇: Windows10电脑重置后右键没有nv