【发布时间】:2020-06-13 11:48:43
【问题描述】:
我尝试在我的模板中显示{{ bgColor }}。
但它只显示 [object Promise]
const { getColorFromURL } = require('color-thief-node')
export default {
data() {
return {
api_url: process.env.strapiBaseUri,
bgColor: this.updateBgColor(this.project),
}
},
props: {
project: Object,
},
methods: {
updateBgColor: async function(project){
return await getColorFromURL(process.env.strapiBaseUri+this.project.cover.url).then((res) => {
const [r, g, b] = res
console.log( `rgb(${r}, ${g}, ${b})` )
return `rgb(${r}, ${g}, ${b})`
})
}
}
}
这个函数看起来可以工作,因为我在 console.log 上得到了结果
rgb(24, 155, 97)
我想我在方法、插件和异步函数的使用之间迷失了。
任何帮助表示赞赏!
【问题讨论】:
标签: vue.js plugins promise nuxt.js