Javascript Vue cli 3:如何使用具有确定路径的静态资产?

Javascript Vue cli 3:如何使用具有确定路径的静态资产?,javascript,vue.js,vue-cli-3,Javascript,Vue.js,Vue Cli 3,我的应用程序有以下地址: https:/firstpath.com/firstsubfolder/app.html 使用我的静态资产的相对路径转到: https:/firstpath.com/firstsubfolder/img/image.png 如何为静态资产使用确定的路径?例如: https:/secondpath.com/secondsubfolder/thirdsubfolder/img/image.png 如果您的资产在https://secondpath.com/second

我的应用程序有以下地址:

https:/firstpath.com/firstsubfolder/app.html
使用我的静态资产的相对路径转到:

https:/firstpath.com/firstsubfolder/img/image.png
如何为静态资产使用确定的路径?例如:

https:/secondpath.com/secondsubfolder/thirdsubfolder/img/image.png

如果您的资产在
https://secondpath.com/secondsubfolder/thirdsubfolder
但如果你的应用程序位于另一个域上,你只需调用你的资产,并为每个资产提供完整的URL即可


如果应用程序URL为
https://firstdomain.com/firstapp/app.html
在那里,您可以从
https://fristdomain.com/anotherdir/assets.js
例如。

如果您的资产在
https://secondpath.com/secondsubfolder/thirdsubfolder
但如果你的应用程序位于另一个域上,你只需调用你的资产,并为每个资产提供完整的URL即可


如果应用程序URL为
https://firstdomain.com/firstapp/app.html
在那里,您可以从
https://fristdomain.com/anotherdir/assets.js
例如。

既然您已经在使用vue cli3,只需在vue.config.js中设置
assetsdir
属性即可。
更多信息请访问

,因为您已经在使用vue cli3,只需在vue.config.js中设置
assetsdir
属性即可。
更多信息请访问

我使用地址为:../assets/${item.image}.png)>如果我将其更改为:https:/secondpath.com/secondsubfolder/thirdsubfolder/img/${item.image}.png)>网页包无法编译我的应用程序,我认为您应该用引号将其连接起来:
require('https://secondpath.com/secondsubfolder/thirdsubfolder/img/'+${item.image}+'.png')
连接字符取决于您所处的文件类型(+用于JS)我使用地址为:../assets/${item.image}.png)>如果我将其更改为:https:/secondpath.com/secondsubfolder/thirdsubfolder/img/${item.image}.png)>Webpack无法编译我的应用程序,我认为您应该用引号连接它:
require('https://secondpath.com/secondsubfolder/thirdsubfolder/img/“++${item.image}+'.png”)
连接字符取决于您所在的文件类型(+用于JS)你能发布一些你使用的模板代码吗?从你下面的一条评论中,我注意到你正在使用
,我想你想要的就是把它当作
来使用。另外,在
https://
@ChiragRavindra之后应该有两个斜杠。很抱歉,事实上,代码和你描述的一模一样。我想漏掉一个斜杠,编辑器t你能发布一些你使用的模板代码吗?从你下面的一条评论中,我注意到你正在使用
,我想你想要的就是把它当作
来使用。另外,在
https://
@ChiragRavindra之后应该有两个斜杠对不起,事实上代码和你描述的一模一样。我错过了一个斜杠,编辑在回答中把反勾号变成了一个引号谢谢,这是正确的防御方式,但我仍然在忍受它。我正在玩vue.config.js,这就是我想到的(不起作用):
module.exports={publicPath:“./”,assetsDir:“../../secondpath.com/secondsubfolder/thirdsubfolder/img/”}
问题是此路径相对于我的outputDir(默认情况下是dist)我仍然无法设置静态资产的绝对路径,因为资产路径位于另一个域上,我建议使用类似
https://secondpath.com/...
然后一切都应该正常。至少我希望如此;)谢谢,这是正确的防御方式,但我仍然在忍受它。我在玩vue.config.js,这就是我想到的(不起作用):
module.exports={publicPath:“../”,assetsDir:“../../secondpath.com/secondsubfolder/thirdsubfolder/img/”}
问题是这个路径与我的outputDir相对(默认情况下为dist)并且我仍然无法设置静态资产的绝对路径,因为资产路径位于另一个域上,我建议使用类似
https://secondpath.com/...
然后一切都应该正常。至少我希望如此;)