search

Home  >  Q&A  >  body text

javascript - How vue-cli extracts public methods and applies them

How to extract the method in the picture and make it into a public part

習慣沉默習慣沉默2741 days ago945

reply all(1)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-06-26 10:52:30

    Write this in methods when instantiating Vue in main.js, and then call $root.link when calling it elsewhere.

    var app = new Vue({
        el: '#app',
        router,
        components: {App},
        template: '<App />',
        methods: {
            link: function(to) { ... }
        },
        ...
    });

    It’s not written in App.vue, thank you @kokradoc for the correction.

    reply
    0
  • Cancelreply