可以的。如下示例:
import store from '@/store/index.js'
export default {
name: "xxx",
props: {
title: {
type: String,
default: store.getters.userInfo.name, //store的值
},
},
}
看样子应该是没取到this.$store
这个加载时机可能有些问题,推荐你做个监听吧,或者mounted里面 created里面给个初始值
写个三元表达式
没看明白要表达的意思,写清楚点呢?
$store 未定义 你 使用的地方 没有 这个属性
贴代码咯