转载: https://www.cnblogs.com/mqxs/p/8972368.html
- #HTML
- <div id="example">
- <p>
- <child :msg="msg"></child>
- </p>
- <p>
- <button @click='props'> 改变 props</button>
- </p>
- </div>
- #JS
- vue.component('child', {
- props: ['msg'],
- computed: {
- value:{
- get:function(){
- return this.msg
- },
- set:function(value){
- this.msg = value;
- }
- }
- },
- watch:{
- msg:function(val,oldval){
- this.value='改变子组件 msg';
- }
- },
- template: '<span>{{ value }}</span>'
- })
- var vm=new Vue({
- el:'#example',
- data:function(){
- return{
- msg:'默认子组件 msg'
- }
- },
- methods:{
- props:function(){
- this.$set('msg','2');
- }
- }
- })
来源: http://www.bubuko.com/infodetail-2901862.html