Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import external template in vue js?

I am beginner to vue js, not sure i am asking correct or not.

I want to make following type of structure for my Laravel 5.3 - Vue Js App.

  1. my-vue.js

     Vue.component('my-component', {
            template: 'template from Catgory.Vue'
     })
    
     new Vue({
        el: '#example'
     })
    
  2. Category.vue

    <template>
        <div>
            // some code goes here
        </div>
    </template>
    
  3. index.blade.php

    <div id="example">
       <my-component></my-component>
    </div> 
    

    How can i use template from Category.vue in template attribute of Vue.component? Or Suggest me better approach.

like image 955
Swapnil Chaudhari Avatar asked Dec 22 '16 16:12

Swapnil Chaudhari


1 Answers

This link can be useful

 Vue.component('my-component', {
   template: require('./Category.html')
 });
 new Vue({
     el: '#example'
 })

Category.html.js

module.exports = `<div>Hello, {{ name }}!</div>`;
like image 154
fingerpich Avatar answered Oct 01 '22 13:10

fingerpich