我正在尝试将图像 src 动态绑定到表单的 URL ../assets/project_screens/image_name.jpg。
我的目录结构如下:
- src
-- assets
---- project_screens
-- profile
---- ProjectList.vue
-- store
---- profile.js
Run Code Online (Sandbox Code Playgroud)
我知道我需要使用 webpackrequire("path/to/image")来帮助 webpack 构建这些图像,但是路径没有解析。
- src
-- assets
---- project_screens
-- profile
---- ProjectList.vue
-- store
---- profile.js
Run Code Online (Sandbox Code Playgroud)
// store/profile.js
projects = [
{
....
},
{
....
img_url: "../assets/project_screens/im1.jpg"
....
}
....
]
Run Code Online (Sandbox Code Playgroud)
如果我使用 URL 字符串而不是动态传递 URL 字符串,它会起作用。环顾堆栈溢出,没有任何解决方案有帮助。我还缺少其他东西吗?
我是承诺世界的新手,所以请在以下情况下启发我:
function promiseDemo(fetch1,fetch2){
return Promise.all([fetch1,fetch2]).then(function(values){
return values[0]+values[1];
});
}
promiseDemo(ajax('sample1.html'),ajax('sample2.html')).then(function(sum){
console.log(sum);
},function(){
console.log('Whoopsie!!!!!');
});
function ajax(file){
var httpRequest=new XMLHttpRequest();
httpRequest.open('GET',file,true);
httpRequest.onreadystatechange=function(){
if( httpRequest.readyState == 4){
if(httpRequest.status == 200){
console.log('success');
console.log(httpRequest.responseText);
return Promise.resolve(httpRequest.responseText);
}else{
console.log('unexpected 400 error');
return 0;
}
}
}
httpRequest.send();
}
Run Code Online (Sandbox Code Playgroud)
上面的代码从两个文件 sample1 和 sample2 中获取示例 html 并仅在两个文件都被检索时将文本附加到 dom。但是即使当 reponseText 符合预期时,我也会将 values[0] 和 values[1] 设为未定义。有什么问题??欢迎提出任何建议,谢谢!!!!