我正在使用新的Vue插件来使用composition API和TypeScript,但有一点我不太明白.
我应该如何键入计算(computed)属性?
import Vue from 'vue'
import { ref, computed, Ref } from '@vue/composition-api'
export default Vue.extend({
setup(props, context) {
const movieName:Ref<string> = ref('Relatos Salvajes')
const country:Ref<string> = ref('Argentina')
const nameAndCountry = computed(() => `The movie name is ${movieName.value} from ${country.value}`);
return { movieName, country, nameAndCountry }
}
})
在这个简单的例子中,我声明了两个ref和一个computed属性来连接它们.VSC告诉我计算(computed)属性返回ReadOnly
类型...但我不能让它工作.