vue无法获取dom

处理过程

watch监听值变化

index.js:33  [Vue warn]: Error in callback for watcher "$store.state.modelsStorageUrl": "TypeError: Cannot set properties of undefined (setting 'modelScene')"
watch: {
   
	"$store.state.modelsStorageUrl":{
   
      handler:(newVal,oldVal)=>{
   
        console.log("watched")
        console.log("oldVal",oldVal);
        console.log("newVal",newVal);
          if(oldVal!==''){
   
            console.log("加载速度快",oldVal)
            this.modelScene = new loadModel(oldVal);
            this.loadModelsUrl()
            console.log(this.modelScene)
          }
          if(oldVal!==newVal){
   
            console.log("加载速度慢",newVal,oldVal)
            console.log("oldVal",oldVal);
            console.log("newVal",newVal);
            this.modelScene = new loadModel(newVal);
            this.loadModelsUrl()
            console.log(this.modelScene)
          }
          if(newVal){
   
            console.log("加载速度慢2",newVal)
            this.modelScene = new loadModel(newVal);
            this.loadModelsUrl()
            console.log("this.modelScene",this.modelScene)
          }
      }
    }
}

this 指向问题

参考文档

  1. vue 生命周期函数不建议使用箭头函数,使用function
  2. this.$nextTick 使用箭头函数。
created() {
   
	this.loadModelsUrl()
},
methods: {
   
	loadModelsUrl(){
   
      this.$nextTick(()=>{
   
            setTimeout(() => {
   

              this.modelScene.showPageViewScene(
                  this.$refs.three_canvas,
                  this.width,
                  this.height
              )
              this.percentage = 100
            }, 2)
      }
      )
    }
}

解决

最后原因 computed 报错 导致页面没有加载DOM,所以this.$refs.three_canvas
无法获取到在这里插入图片描述

相关推荐

  1. Vue3: 获取元素DOM的方法

    2024-01-05 19:14:04       49 阅读
  2. vue项目获取 iframe 中的DOM元素

    2024-01-05 19:14:04       59 阅读
  3. Uniapp 和Vue3 小程序 获取页面dom 方法

    2024-01-05 19:14:04       41 阅读
  4. React获取DOM节点

    2024-01-05 19:14:04       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-05 19:14:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-05 19:14:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-05 19:14:04       82 阅读
  4. Python语言-面向对象

    2024-01-05 19:14:04       91 阅读

热门阅读

  1. 什么是Vue-响应式数据

    2024-01-05 19:14:04       61 阅读
  2. 2023年终总结

    2024-01-05 19:14:04       57 阅读
  3. LeetCode 28.找出字符串中第一个匹配项的下标

    2024-01-05 19:14:04       66 阅读
  4. 【PHP】PHP实现RSA加密,解密,加签,验签

    2024-01-05 19:14:04       62 阅读
  5. IDEA UML图

    2024-01-05 19:14:04       57 阅读
  6. LeetCode 32:最长有效括号

    2024-01-05 19:14:04       53 阅读
  7. 安装Paddle-ChatDocuments大模型

    2024-01-05 19:14:04       50 阅读
  8. 力扣labuladong一刷day52天LRU算法

    2024-01-05 19:14:04       58 阅读