【发布时间】:2021-11-21 17:07:29
【问题描述】:
我正在关注关于如何在我的 css 中使用道具的答案 (Vue is it possible to use a prop for styling? (SCSS/ SASS))。我想传入initWidth 作为道具,但它的默认设置为300。然后我将初始数据设置为等于该道具,以便计算属性可以访问它。尽管Property 'baseWidth' does not exist on type '{ cssProps(): void; }'.,但我收到了打字稿错误。我需要为此创建一个新界面吗?
props: {
initWidth: {
type: Number,
default: 300,
}
},
data() {
return {
baseWidth: this.initWidth
}
},
computed: {
cssProps() {
return {
'--baseWidth': this.baseWidth + "px",
}
}
}
【问题讨论】:
标签: typescript vue.js