最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】vuejs中computed中调用methods函数报错:TypeError Cannot read property visibleValue of undefined

JS crifan 575浏览 0评论
折腾:
【未解决】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
vue.js – Using Computed Properties inside Methods in vueJs – Stack Overflow
javascript – Vue.js, Functions inside methods are not found – Stack Overflow
javascript – Uncaught TypeError: not a function when calling method from data in Vue – Stack Overflow
javascript – How to write this function as a computed property in Vue – Stack Overflow
vuejs2 – How to access a computed property from a method in a Single File Component with Vue.js – Stack Overflow
vuejs computed call methods
Calling method in Computed property – Get Help – Vue Forum
Call method when computed property returns true – Get Help – Vue Forum
How to run a computed property without calling it from html template? – General Discussion – Vue Forum
Computed vs. methods vs. mounted vs. created – General Discussion – Vue Forum
Call object method in Compute method in Vue component – Get Help – Vue Forum
Computed Properties and Watchers — Vue.js
好像就不支持:
从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>
javascript – Vuejs: where should I place some common js util in a vue-router SPA? – Stack Overflow
后来发现是:
自己语法写错了,应该是:
    // 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 Properties and Watchers — Vue.js
是:
// ...
computed: {
  someProperty: {
    // getter
    get: function () {
      ...
    },
    // setter
    set: function (newValue) {
      ...
    }
  }
}
// ...
自己之前写错成:
computed: {
  someProperty: (){
    ...
  }
了,才报错的。才找不到this.xxx中的xxx变量的。

转载请注明:在路上 » 【已解决】vuejs中computed中调用methods函数报错:TypeError Cannot read property visibleValue of undefined

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
88 queries in 0.127 seconds, using 20.47MB memory