美文网首页
vue 渲染函数的执行

vue 渲染函数的执行

作者: 苍老师的眼泪 | 来源:发表于2022-10-08 00:08 被阅读0次

当渲染函数的依赖没有发生变化时,渲染函数不会执行,一下change 执行一次跟执行多次效果都是一样的,firstname 被设置为 Xie 之后不再改变,重复赋相同的值不会触发渲染函数的执行。

<script>
import { h } from 'vue';

export default {
  data() {
    return {
      firstname: 'Edison',
      lastname: 'Hsieh'
    }
  },
  computed: {
    fullname() {
      return this.firstname + ' ' + this.lastname
    }
  },
  methods: {
    // 
    change() {
      this.firstname = 'Xie'
    }
  },
  render() {
    console.log('渲染函数执行')
    return h('button', { id: 'foo', class: 'bar', onClick: this.change }, [this.fullname])
  }
}

</script>

相关文章

网友评论

      本文标题:vue 渲染函数的执行

      本文链接:https://www.haomeiwen.com/subject/oyfgartx.html