快捷搜索: 王者荣耀 脱发

vue2在method()中处理的数据,在mouted()中调用使用

vue2在method()中处理的数据,在mouted()中调用使用

1.vue2在method()中处理的数据,在mouted()中调用使用,并且在axios请求后台的数据为异步时的操作

问题描述: 1.数据在method()中获取到的后台的数据没法传递到mouted()中进行传值展示,主要是因为axios()在使用时,是异步操作,使用async()与await()在mouted()调用时,要先await()操作,并且在method()方法中要使用that的方式接收值,这样就可以获取到了。 如下步骤展示操作:

method()中获取后台的值,进行处理的操作: 代码部分:

async  dataNode () {
          
   
                await this.axios.get(http://www.equipment.com/showNodeOperation.php/, {
          
   

                })
                    .then((successResponse) => {
          
   
                        var that = this
                        that.nodeTree = successResponse.data.data

                        // let a = {
          
   }
                        // a.shuzu = [1, 2, 3]
                        // a.zhangzu = [5, 6, 7]
                        // console.log(测试添加, a)
                        // console.log(打印后台传递的值, this.res)
                        // return this.nodeTree
                    })
            },

mouted()方法中展示: 代码部分:

mounted () {
          
   
            // let that = this
            this.jsPlumb = jsPlumb.getInstance()
            this.$nextTick(async () => {
          
   
                var that = this
                // 默认加载流程B的数据、在这里可以根据具体的业务返回符合流程数据格式的数据即可
                // this.dataReload(getDataB())
                await this.dataNode()
                this.dataReload(that.nodeTree)

                // console.log(22222222222222, that.nodeTree)
            })
            // this.isRealConnect()
        },

注意:注意是处理同步,异步的问题,数据同步获取不到,或者是先获取,后传值,导致拿不到传递过来的数据,主要进行数据先传值,后接受,再处理的流程。

经验分享 程序员 微信小程序 职场和发展