[英]firebase storage not running unless code changed with hot reload in vuejs2
我正在创建一个图像加载应用程序。 图像详细信息存储在Firestore中,并已成功检索。 然后使用映像名称创建Firebase存储的路径。 然而,功能Firebase.storage.ref(...path).getDownloadURL()
不运行在所有的,包括回调.then(...)
或.catch(...)
除非在“ npm run serve”运行时在创建的方法中更改了代码。 提前致谢。
在运行Ubuntu 19的计算机上,在npm 6.4.1上使用Firebase版本5.11.0,在节点v10.15.3上使用。Vue-cli版本3.7.0。 也使用eslint
import firebase from 'firebase';
export default {
name:'imageView',
props: ["imaGes"],
data(){
return{
imageURLs:[]
}
},
created(){
console.log('start')
var storage = firebase.storage();
this.imaGes.forEach(iMaGe => {
//console.log(iMaGe.image_name)
var storageRef = storage.ref('images_img/'+iMaGe.image_name);
console.log('reference completee')
storageRef.getDownloadURL().then(url =>{
//console.log('bo')
const data = url;
this.imageURLs.push(data);
//console.log('get completed')
//console.log('hi')
})
.catch(err=>{
console.log(err)
})
});
console.log('completed')
}
}
数组imageURL应使用Firebase Storage的下载URL进行填充。
您需要使用Promise.all()
并行执行对异步getDownloadURL()
方法的调用。
import firebase from 'firebase';
export default {
name:'imageView',
props: ["imaGes"],
data(){
return{
imageURLs:[]
}
},
created(){
console.log('start')
var storage = firebase.storage();
const promises = [];
this.imaGes.forEach(iMaGe => {
var storageRef = storage.ref('images_img/'+iMaGe.image_name);
console.log('reference completee')
promises.push(storageRef.getDownloadURL());
});
return Promise.all(promises)
.then(results => {
this.imageURLs = results;
})
.catch(err=>{
console.log(err)
});
}
}
另请注意iMage.image_name
的错字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.