Vuejs can't access refs from component

后端 未结 7 1352
终归单人心
终归单人心 2020-12-17 07:45

I am trying to get the canvas element which is inside a template of a component, found great documentations for vuejs1 but not for vuejs2 where "ref" is the only w

7条回答
  •  爱一瞬间的悲伤
    2020-12-17 08:22

    @Dan Levin 's answer works.

    methods: {
    fecthData() {
        this.data ={ ... }; // assume the fetched data have changed DOM here.
    
        this.$nextTick(() => {
          console.log(this.$refs); // returns obj
          console.log(this.$refs.target); // returns el
        });
    }
    

    this works also with v-for.

提交回复
热议问题