component

1、使用-初步

必须要父,且先Vue.component()再new Vue()

html:
<div id="box">
    <my-c></my-c>
</div>

js:
Vue.component('my-c',{
    template:'<div>asdasd</div>'
});
new Vue({
    el:"#box"
});

渲染:
<div id="box">
  <div>asdasd</div>
</div>

2、传值

var x={a:1,b:2};
Vue.component('my-c',{
    template:'.............. {{a}}  .......    {{b}}    ....       ',
    data:function(){
        return x;
    }
});

3、事件

<span v-on:click="no">点我</span>
Vue.component('my-c',{
    template:'.............. {{a}}  .......    {{b}}    ....       ',
    data:function(){
        return x;
    },
    methods:{
        no:function(){
            console.log(1111);
        }
    }
});

我就纳闷了,报错

Uncaught TypeError: n.apply is not a function at HTMLDivElement.invoker (vue.min.js:6)

原文地址:https://www.cnblogs.com/hhweb/p/6757021.html