登录

javascript - vue在computed中使用$nextTick方法无法动态更新dom

正在做自己的个人网站,需要通过url参数的变化来动态更新页面内容,根据教程写了这样的代码,但却达不到想要的效果。vue框架是1.0版本的,在项目中使用了vue-router和vue-infinite-loading

代码如下:

  computed: {
    tagId: {
      get: function () {
        return this.$route.params.tag
      },
      set: function () {
        this.list = []
        this.$nextTick(() => {
          this.$broadcast('$InfiniteLoading:reset')
        })
      }
    }
  },
  methods: {
    onInfinite () {
      this.$http.get('artical-list/tag/' + this.tagId + '/page/' + (this.list.length / 10 + 1)).then((res) => {
        if (res.data.length) {
          this.list = this.list.concat(res.data)
          this.$broadcast('$InfiniteLoading:loaded')
        } else {
          this.$broadcast('$InfiniteLoading:complete')
        }
      })
    }
  }

求解,谢谢!

附:vue-infinite-loading的文档:
https://peachscript.github.io...!/getting-started/with-filter

# JavaScript
伊谢尔伦伊谢尔伦2184 天前554 次浏览

全部回复(1) 我要回复

  • PHPzhong

    PHPzhong2017-04-11 13:34:46

    set函数少了一个参数,这部分代码没有看出tagId有修改过

    回复
    0
  • 取消回复发送