vue--子组件修改数据传递给父组件

子组件代码:
<span class="block positive" @click="select(2,$event)" :class="{'active':selectType===2}">{{desc.all}}<span class="count">{{ratings.length}}</span></span>
<div class="switch" @click="toggleContent" :class="{'on':onlyContent}">
    <span class="icon-check_circle"></span>
    <span class="text">只看有内容的评价</span>
  </div>

methods: {
    select (type, event) {
      if (!event._constructed) {
        return
      }
      this.$emit('select', type)
    },
    toggleContent (event) {
      if (!event._constructed) {
        return
      }
      this.$emit('toggle')
    }
  }

父组件代码:

<ratingselect @select="selectRating" @toggle="toggleContent" :select-type="selectType" :only-content="onlyContent" :desc="desc" :ratings="food.ratings"></ratingselect>
methods: {
  selectRating (type) {
      this.selectType = type
      this.$nextTick(() => {
        this.scroll.refresh()//实时更新better-scroll的高度,$nextTick异步更新dom
      })
    },
    toggleContent () {
      this.onlyContent = !this.onlyContent
      this.$nextTick(() => {
        this.scroll.refresh()//实时更新better-scroll的高度,$nextTick异步更新dom
      })
    }
}


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页