码迷,mamicode.com
首页 > 其他好文 > 详细

vue 组件小例子 this.$parent

时间:2018-06-23 15:42:55      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:his   ons   number   otl   事件   例子   app   ops   new   

<body>

 
<div id="app">
 
<goods :name=‘name‘ :price=‘price‘ :num=‘num‘></goods>
<!--进行原始的点击事件 局部注册-->
 
</div>
</body>

  

var vm = new Vue({

            el: "#app",
            data: {
                name: "苹果",
                price: 10,
                num: 1
            },        
            components:{
                "goods":goods
            }
        });

var goods = {
        template: "<div><p>名字:{{name}}</p><p>价格:{{price}}</p><p>数量:{{num}}</p><p>总价:{{totle}}</p><br /><button @click=‘jia‘ >+</button><br /><button  @click=‘jian‘>-</button></div>",
            props: ["name",‘price‘,‘num‘],
            
            computed:{
                totle:function(){
                    
                    console.log(this)
                    return this.num*this.price
                    
                }
            },methods: {
                jia: function() {
                    
                    this.$parent.num++    zhixiang指向vm.num
                },

            
                jian: function() {
                    
                    this.$parent.num--
                }

            }
            
        }

  

vue 组件小例子 this.$parent

标签:his   ons   number   otl   事件   例子   app   ops   new   

原文地址:https://www.cnblogs.com/ydam/p/9217096.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!