📜  如何在 vue js 中传递方法 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:51.335000             🧑  作者: Mango

代码示例1
let Post = Vue.extend({
  props: {
    onClicked: Function,
    post: Object
  },
  template: `
      
`, methods: { clicked() { this.onClicked({ id: this.post.id }); } } }); let PostsFeed = Vue.extend({ data: function() { return { posts: [ {id: 1, title: 'Roadtrip', content: 'Awesome content goes here'}, {id: 2, title: 'Cool post', content: 'Awesome content goes here'}, {id: 3, title: 'Motorcycle', content: 'Awesome content goes here'}, ] } }, template: `
`, methods: { clicked(event) { alert(event.id); } }, components: { post: Post } }); new Vue({ el: '#app', components: { 'post-feed': PostsFeed } });