How to load external html file in a template in VueJs

后端 未结 3 374
醉梦人生
醉梦人生 2021-01-04 03:15

I\'m new to vue js. I\'m just creating a simple project where I just include vuejs through CDN. not using node/npm or cli.

I keep all my html markup in single html

3条回答
  •  粉色の甜心
    2021-01-04 03:35

    It's actually remarkably easy, but you need to keep something in mind. Behind the scenes, Vue converts your html template markup to code. That is, each element you see defined as HTML, gets converted to a javascript directive to create an element. The template is a convenience, so the single-file-component (vue file) is not something you'll be able to do without compiling with something like webpack. Instead, you'll need to use some other way of templating. Luckily there are other ways of defining templates that don't require pre-compiling and are useable in this scenario.

    1 - string/template literals

    example: template: '

    {{myvar}}
    '

    2 - render function

提交回复
热议问题