我需要在Tailwind类中使用Vue prop 。
类是bg-[url('address')]
(背景图像),其中address
是一个prop。
但无论我怎么尝试,我总是得到错误:
模块未找到:错误:无法解析此"website“。
我试探着:
`bg-[url(${this.icon})]`
"`bg-[url(${this.icon})]`"
'bg-[url('+this.icon+')]'
字符串
我也试着在computed中使用这种语法。像这样:
classIcon() {
return `bg-[url(${this.icon})]`
}
型
我的完整代码组件:
模板:
<template>
<div class="flex items-center rounded-lg bg-gray-100 p-4 font-lato">
<div class="bg-no-repeat w-full" :class=`bg-[url(${this.icon})]`>trstestes</div>
<div class="flex flex-col">
<p>
<span class="font-bold">
{{ title }}
</span>
{{ benefit }}
</p>
</div>
</div>
</template>
型
脚本:
export default {
props: {
icon: {
type: String,
require: true,
default: "Ícone",
},
}
}
型
通过计算:
模板:
<template>
<div class="flex items-center rounded-lg bg-gray-100 p-4 font-lato">
<div class="bg-no-repeat w-full" :class="classIcon">trstestes</div>
<div class="flex flex-col">
<p>
<span class="font-bold">
{{ title }}
</span>
{{ benefit }}
</p>
</div>
</div>
</template>
型
脚本:
classIcon() {
return `bg-[url(${this.icon})]`
}
型
1条答案
按热度按时间pkbketx91#
你不应该使用这样的tailwind类,因为tailwind不能使用这样的类。你可以做的是在html根目录下创建一个css变量,然后修改这个变量!
字符串
然后在脚本中执行:
型