JavaScript 需要来自变量
JavaScript Require From Variable
我正在使用以下内容:
props: {
backgroundImagePath: {
type: String,
required: true,
default: '@/static/images/9.jpeg'
}
}
:style="{
backgroundImage: `url(${require(backgroundImagePath)})`
}"
这给了我以下错误:
Cannot find module '@/static/images/9.jpeg'
:style="{
backgroundImage: `url(${require('@/static/images/9.jpeg')})`
}"
但是可以正常工作 - 我不确定为什么?
对于上下文,我使用的是 NuxtJS。
props: {
backgroundImagePath: {
required: true,
default: require('@/static/images/9.jpeg')
}
}
:style="{
backgroundImage: `url(${backgroundImagePath})`
}"
更改 backgroundImagePath
道具默认值似乎可以解决此问题。
我正在使用以下内容:
props: {
backgroundImagePath: {
type: String,
required: true,
default: '@/static/images/9.jpeg'
}
}
:style="{
backgroundImage: `url(${require(backgroundImagePath)})`
}"
这给了我以下错误:
Cannot find module '@/static/images/9.jpeg'
:style="{
backgroundImage: `url(${require('@/static/images/9.jpeg')})`
}"
但是可以正常工作 - 我不确定为什么?
对于上下文,我使用的是 NuxtJS。
props: {
backgroundImagePath: {
required: true,
default: require('@/static/images/9.jpeg')
}
}
:style="{
backgroundImage: `url(${backgroundImagePath})`
}"
更改 backgroundImagePath
道具默认值似乎可以解决此问题。