How can I share a method between components in Vue.js?

前端 未结 4 1501
野趣味
野趣味 2020-12-13 03:55

Check out this simple shopping cart demo:

http://plnkr.co/edit/CHt2iNSRJAJ6OWs7xmiP?p=preview

A user can pick a veggie and a fruit, and it will be added into

4条回答
  •  无人及你
    2020-12-13 04:17

    If you are trying to share the same component logic between or along multiple vue template and layout, you can simply try this approach below:

    before:

    a.vue

    
    
    
    

    b.vue

    
    
    
    
    

    after:

    a.vue

    
    
    
    

    b.vue

    
    
    
    

    shared.js

    export default {
      props: {
        title: String
      },
      data() {
        return {
          datetime: new Date()
        }
      }
    }
    
    

提交回复
热议问题