Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

vue 如何拿到this.data后的回调函数

<script>
  export default {
    data () {
      return {
        radio: '1'
      };
    },
    methods: {
      change(){
        this.radio = '2' //这里该怎么拿到this.radio的回调函数
      }
    }
  }
</script>

用watch监听可以达到效果,不过有没有像react这样,同样是set data数据,react的回调函数是这样写的 ↓

this.setState({data:123},() => {
     console.log(this.state.data) //123 
  })

那么vue的该怎么写呢~~

问题详情如上,在这里先感谢各位大哥们的解答,小弟感激不尽!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

vue更改data上的数据是同步的,因为你直接改的就是this.data = ...;而不是像react那样调用一个函数,如果你是想更新后的数据渲染到视图再触发回调则使用nextTick API


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...