1. 程式人生 > >vue--子元件修改資料傳遞給父元件

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
      })
    }
}


相關推薦

vue--元件修改資料傳遞元件

子元件程式碼:<span class="block positive" @click="select(2,$event)" :class="{'active':selectType===2}">{{desc.all}}<span class="count"&

vue---調子 $refs (把元件資料元件調 $emit (把子元件資料元件)

ps:App.vue 父元件   Hello.vue 子元件 App.vue : <template> <div id="app"> <input type="

angular2父子元件資料傳遞元件元件傳遞資料

父元件---->子元件 <my-component  [input]="myvalue" ></my-component> 這是單一使用向子元件寫入一組資料, 這樣我們在my-component元件裡面使用@Input() input: an

Angular2父子元件之間資料傳遞:父子元件共享服務通訊

​父子元件共享同一個服務,利用該服務實現雙向通訊 首先定義服務:parentService.ts(服務) import {Injectable} from "@angular/core"@Injectable()export class ParentService {n

vue 元件非同步值傳遞元件 元件進行資料處理

文章目錄 模擬非同步 問題描述 原因 解決 模擬非同步 父元件 <template> <div> 父元件 <child :child-data="asyncData" ><

Vue元件的方法傳遞元件呼叫(評論列表例子)

Vue把父元件的方法傳遞給子元件呼叫(評論列表例子) 效果展示: 相關Html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>T

Vue學習之路(六)---元件元件之間的資料傳遞

前面我講了基本元件的寫法,現在一起學下父元件怎樣傳遞資料到子元件,以及子元件傳遞資料到父元件的 1.父元件傳遞資料到子元件 1.1 通過props傳遞 父元件App.vue中 <component-a big-num=98></component-a&g

vue元件調子元件 $refs (把元件資料元件

父元件: <el-dialog title="" @close="refresh" :visible.sync="userRoleVisible" @open="showAuthEvent"> <user-role-panel ref="authP

vue中子元件傳遞資料元件

  傳送者: modifyName:是接受者的鍵,也就是傳送和接收的唯一標識 itemObj:是一個物件 this.$emit("modifyName",this.itemObj);   接受者: <common-table 是一個自定義元

Vue 父子元件資料傳遞修改和更新

父子元件之間的資料關係,我這邊將情況具體分成下面4種: 父元件修改子元件的data,並實時更新    子元件通過$emit傳遞子元件的資料,this.$data指當前元件的data(return{...})裡的所有資料, this.$emit('data',this.

Vue.js的元件(二)元件元件資料聯絡 之

假設有如下元件: /*js*/ Vue.component('my-button',{ tempalte:'<button>一個按鈕</button>' }) var app3 = new Vue({ el:'#ap

angular2.0父子元件通訊---如何通過元件屬性將資料傳遞元件

1.input properties, typically adorned with @Input decorations. import{Component,Input}from'@angu

vue父子元件props傳值,如何在元件method裡拿到元件資料

子元件掛載的時候,props傳值,資料掛載命名:用駝峰命名法命名,在子元件在methods裡才可以通過this.xx獲取。注意命名要規範。父元件通過props傳值給子元件,子元件在methods裡要拿到父元件傳遞過來的資料有2種情況:第一種:父元件傳遞的引數是固定的,data

react元件元件資料傳遞

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=de

淺入深出Vue元件資料傳遞

上一篇瞭解了元件的概念及在使用中需要注意的地方。在面對單個元件邏輯複雜需要拆分時,難免會遇到父子元件之間資料傳遞的問題。那麼我們來了解一下在父子元件之間進行資料傳遞時需要遵循哪些約定,以及要注意哪些問題。 如何傳遞 父元件向子元件在進行傳遞時,使用的是 prop特性進行傳遞。 約定 老規矩, 在使用前我們首先

Vue父子元件資料傳遞

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>父子元件傳值</title> <script src="./v

flutter widget 混合管理 元件傳值元件

這裡最重要的就是定義@required this.onChanged class SonWidget extends StatefulWidget { SonWidget ({Key key,this.weibo,@required this.onChanged}):super(key:key);

flutter widget 混合管理 元件傳值元件

這裡最重要的就是定義@required this.onChanged class SonWidget extends StatefulWidget { SonWidget ({Key key,this.weibo,@required this.onChanged}):super(key:k

React 元件之間的傳值--尤其元件元件傳值

元件之間的傳值有三種情況, 1.父元件給子元件傳值 2.子元件給父元件傳值 3.兄弟元件相互傳值 1.父元件給子元件傳值 子元件中通過props 封裝屬性,當父控制元件用到子元件是 給屬性賦值 例: 子元件 import React from 'react

react 元件元件傳值

class Parent extends React.Component{ constructor(){ super(); this.state = { msg:"" } } show(v){ this.