Fred Burette
Fred Burette

Reputation: 37

Vue.js Component registration template

Here a very simple component

const MyComponent = Vue.component('my-component', {
   data () {
      // data here...
   },
   methods: {
      // methods here...
   },
   template: '<p>Hello, world !!!</p>'
});

Is it a way to use a external file to write html code <p>Hello, world!</p> instead of the string template ?

I know it is a way with single file components (https://v3.vuejs.org/guide/single-file-component.html).

But unfortunately, i can't follow this way because in my context, i can't use tools like Vue CLI for example

Upvotes: 1

Views: 195

Answers (1)

match
match

Reputation: 11060

The value of template in your example can be sourced from anywhere. So its possible to do:

template.js:

export default {
  return "<p>Hello, world!!!</p>"
}

component.js

import template from 'template'

const MyComponent = Vue.component('my-component', {
  template: template,
});

Upvotes: 1

Related Questions