Vue js error: Component template should contain exactly one root element

后端 未结 8 2141
予麋鹿
予麋鹿 2020-11-29 04:37

I don\'t know what the error is, so far I am testing through console log to check for changes after selecting a file (for uploading).

When I run $ npm run watc

8条回答
  •  情书的邮戳
    2020-11-29 04:56

    For a more complete answer: http://www.compulsivecoders.com/tech/vuejs-component-template-should-contain-exactly-one-root-element/

    But basically:

    • Currently, a VueJS template can contain only one root element (because of rendering issue)
    • In cases you really need to have two root elements because HTML structure does not allow you to create a wrapping parent element, you can use vue-fragment.

    To install it:

    npm install vue-fragment
    

    To use it:

    import Fragment from 'vue-fragment';
    Vue.use(Fragment.Plugin);
    
    // or
    
    import { Plugin } from 'vue-fragment';
    Vue.use(Plugin);
    

    Then, in your component:

    
    

提交回复
热议问题