当温泉模式nuxtjs开发的应用,这些资产在引用/_nuxt/vendor.a0f2fda15695e202a186.js中index.html。
是否可以使用相对网址(没有第一个斜杠)来引用这些文件?
(类似<script type="text/javascript" src="_nuxt/vendor.a0f2fda15695e202a186.js"></script>)
可能不会。
参见 https://github.com/nuxt/nuxt.js/issues/1380
您想要资产的“相对路径”的原因是因为SPA(或资产)不在域的根目录中。例如:
您的SPA不在https://my-domain.com/
但是在https://my-domain.com/my-app/
转到nuxt.config.js并编辑以下属性。
build: {
// Set the absolute path where the assets are.
// https://nuxtjs.org/api/configuration-build#publicpath
publicPath: 'https://my-domain.com/my-app/',
},
router: {
// Set the "Base" of the router.
// https://router.vuejs.org/en/api/options.html#base
base: '/my-app/'
},
link: [
// Do this if you have files that are located at /static/
// https://nuxtjs.org/guide/assets#static
{
rel: 'stylesheet',
type: 'text/css',
href: '/my-app/myStyleSheet.css'
}
]
Run Code Online (Sandbox Code Playgroud)
您应该在 nuxt.config.js 文件的路由器配置中将基本参数设置为“my-app”:
module.exports = {
router: {
base: '/my-app/'
}
}
Run Code Online (Sandbox Code Playgroud)
参见 文档https://nuxtjs.org/api/configuration-router/#base
| 归档时间: |
|
| 查看次数: |
1200 次 |
| 最近记录: |