Home  >  Q&A  >  body text

javascript - vue component event problem

How to call the js object method in the vue component?
Now call triggers Uncaught TypeError: cook.tag is not a function
Uncaught TypeError: cook.tag is not a function

Where cook.tag is the external objct method, the solution

var cook={}
cook.tag = function(id) {
    alert(id)
}
Vue.component('cook-tag', {
    template: '<p class="cook-tag ui-nowrap-multi"><span class="tag-item" v-for="item in list"  v-on:click="cookview(item)" >#{{item}}</span></p>',
    data() {
        return {
            list:[],
        }
    },
    props: ['tags'],
    created(){
         this.list = this.tags.split(",") || [];
    },
    methods:{
        cookview:function(tag) {
            cook.tag(tag)
        }
    }
});
某草草某草草2710 days ago419

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-18 11:03:42

    Is your cook in another file? Then you need to import the file of the registered component below.

    reply
    0
  • Cancelreply