可以在 Vue 2 路由器中包含 html "partial" 模板(未嵌入 js)吗?
Possible to include an html "partial" template (not embedded in js) in Vue 2 router?
我知道我能做到:
const Foo = {
template:
'<div>bar</div>'
}
const routes = [
{ path: '/foo', component: Foo }
]
但我宁愿以某种方式包含一个 html 文件,例如:
const routes = [
{ path: '/foo', component: {template: require('foo.html')} }
]
...不使用 Webpack、Browserfy 或类似的东西(我试图让事情变得简单)。
创建者 Evan You 在这里解释了为什么他不想使用 templateURLs https://vuejs.org/2015/10/28/why-no-template-url. So, no what you want isn't possible. Now SSR does give some opportunities to structure your app in the way you are talking about. Especially if you are using something like nuxt.js 但是,这仍然包括构建步骤。
我知道我能做到:
const Foo = {
template:
'<div>bar</div>'
}
const routes = [
{ path: '/foo', component: Foo }
]
但我宁愿以某种方式包含一个 html 文件,例如:
const routes = [
{ path: '/foo', component: {template: require('foo.html')} }
]
...不使用 Webpack、Browserfy 或类似的东西(我试图让事情变得简单)。
创建者 Evan You 在这里解释了为什么他不想使用 templateURLs https://vuejs.org/2015/10/28/why-no-template-url. So, no what you want isn't possible. Now SSR does give some opportunities to structure your app in the way you are talking about. Especially if you are using something like nuxt.js 但是,这仍然包括构建步骤。