search

Home  >  Q&A  >  body text

javascript - How to use Vue to write a component and only use it on some traditional html pages?

1 Existing component written using vue example
2 If registered globally in app.js, any html page can be used normally
3 But if this component is only used on one page, how to Register this component locally on this page?

为情所困为情所困2713 days ago687

reply all(2)I'll reply

  • 某草草

    某草草2017-06-12 09:30:18

    Just instantiate vue in your traditional page, introduce your component, and register it in the currently instantiated vue

    var Child = {
      template: '<p>A custom component!</p>'
    }
    new Vue({
      // ...
      components: {
        // <my-component> 将只在父模板可用
        'my-component': Child
      }
    })

    reply
    0
  • 習慣沉默

    習慣沉默2017-06-12 09:30:18

    You need to read the Vue documentation 3~4 times and register locally

    import YourComponent from 'your-component';
    export default{
        components: { YourComponent }
    }

    reply
    0
  • Cancelreply