我想为我的计算器获取 prop 数据。这是代码
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
props: {
color: String,
shape: String,
},
computed: {
theme(): string {
const args: string[] = props.color.split('-') //Cannot find name 'props'
let var_1:string = args[0]
return var_1
}
}
})
</script>
我试着用“这个.颜色”,它也不起作用
1条答案
按热度按时间bmvo0sr51#
通过
this
访问是正确的,但Typescript会抱怨,因为this.color
可能未定义。您可以将属性设置为required,或者让计算的theme
处理undefined。下面是所需的颜色:
或者你可以用类似这样的方法来处理未定义的值: