折腾:
【未解决】vuejs加上属性变量值
期间,代码:
<img class="switch_NXMLE" :style="{'visibility': nxmleVisibility }" src="../../assets/control_room/switch_circle_closed.png" width="46" height="28">
computed: {
...mapGetters([
'name'
]),
nxmleVisibility: () => {
console.log('into computed nxmleVisibility')
return this.visibleValue(this.isNxmleVisibie)
}
},
methods: {
visibleValue(isVisible) {
console.log('isVisible=%o', isVisible)
const curVisibleValue = isVisible ? 'visible' : 'hidden'
console.log(`${isVisible} -> ${curVisibleValue}`)
return curVisibleValue
},报错:
vue.runtime.esm.js:619 [Vue warn]: Error in render: "TypeError: Cannot read property 'visibleValue' of undefined" found in ---> <Dashboard> <AppMain> at src/layout/components/AppMain.vue vue.runtime.esm.js:1888 TypeError: Cannot read property 'visibleValue' of undefined at VueComponent.nxmleVisibility (index.vue?c189:29)

vuejs computed call methods functions TypeError
vuejs computed call methods
好像就不支持:
从computed中调用methods中的函数??
【已解决】vuejs中想办法把公共函数提取出来
期间还是报错找不到变量:
vue.runtime.esm.js:619 [Vue warn]: Error in render: "TypeError: Cannot read property 'isNxmleVisibie' of undefined" found in ---> <Dashboard> at src/views/dashboard/index.vue <AppMain> at src/layout/components/AppMain.vue <Layout> at src/layout/index.vue <App> at src/App.vue <Root>

后来发现是:
自己语法写错了,应该是:
// nxmleVisibility: () => {
nxmleVisibility: {
// getter
get: function() {
console.log('into computed nxmleVisibility')
// console.log('this.isNxmleVisibie=', this.isNxmleVisibie)
// return this.visibleValue(this.isNxmleVisibie)
return visibleValue(this.isNxmleVisibie)
// return this.isNxmleVisibie ? 'visible' : 'hidden'
}
},【总结】
vuejs中computed的函数的语法,参考官网
是:
// ...
computed: {
someProperty: {
// getter
get: function () {
...
},
// setter
set: function (newValue) {
...
}
}
}
// ...自己之前写错成:
computed: {
someProperty: (){
...
}了,才报错的。才找不到this.xxx中的xxx变量的。
转载请注明:在路上 » 【已解决】vuejs中computed中调用methods函数报错:TypeError Cannot read property visibleValue of undefined