How did Vue.js configure templateUrl in the same way as Angular.js did?

I like the simplicity of Vue.js, but I do not want to install it using a browser or webpack. I prefer something like templateUrl in Angular, so I can directly serve a partial page (usually a component) using Nginx. How can I configure this? It was not officially offered, it is difficult to get help there.

+4
source share
1 answer

Vue has nothing built in for this, as far as I can tell, but you could use asynchronous components to fake it if you want.

Vue.component('example', function (resolve, reject) {
  $.get('templates/example.html').done(function (template) {
    resolve({
      template: template
    })
  });
});

- HTML.

<div id="app"></div>

<template id="example">
  <div>
    <h1>{{ message }}</h1>
  </div>
</template>

:

new Vue({
  el: '#app',
  components: {
    example: {
      template: '#example',
      data: function () {
        return {
          message: 'Yo'
        }
      }
    }
  }
});

, , , -, . , vueify.

+6

Source: https://habr.com/ru/post/1611075/


All Articles