亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

訪問Vue JS實例監視對象內的$ refs數組

訪問Vue JS實例監視對象內的$ refs數組

qq_遁去的一_1 2021-03-30 13:14:10
我正在構建一個Vue JS SPA,并且在v-app內部有一個Vuetify數據表。我正在嘗試在監視對象內為數據表內的filteredItems計算屬性設置一個變量,但是我不確定如何訪問實例內的$ refs數組。我知道可以使用以下方法在實例內訪問數據:this.$refs['prospectsTable'].filteredItems但是,相同的引用名稱在watch對象中不起作用。我試過了:$refs['prospectsTable'].filteredItems: function(newItems) {            console.log(newItems);        }&this.$refs['prospectsTable'].filteredItems: function(newItems) {            console.log(newItems);        }我如何訪問watch函數內部的$ refs數組?var p = new Vue({    el: '#prospectsApp',    data: () => ({}),     watch: function() {        // How can i access the $refs array inside of the watch function?        $refs['prospectsTable'].filteredItems: function() {        }    }});<div id="prospectsApp">    <v-app id="inspire" v-cloak>        <v-data-table ref="prospectsTable" v-model="selected" :headers="headers" :items="prospects" :pagination.sync="pagination" select-all item-key="id" class="elevation-1" >             <template v-slot:headers="props">                <tr>                    <th><v-checkbox :input-value="props.all" color="#c79121" :indeterminate="props.indeterminate" primary hide-details @click.stop="toggleAllSelected"></v-checkbox></th>                    <th v-for="header in props.headers" :key="header.text"                        :class="['column sortable', pagination.descending ? 'desc' : 'asc', header.value === pagination.sortBy ? 'active' : '']"                        @click="changeSort(header.value)">                        <v-icon small>arrow_upward</v-icon>                        @{{ header.text }}                    </th>                </tr>            </template>                    </td>                </tr>            </template>            <template slot="no-data">                <p class="text-xs-center">No Data</p>            </template>                                        </v-data-table>    </v-app></div>
查看完整描述

2 回答

?
森欄

TA貢獻1810條經驗 獲得超5個贊

由于聲明組件的位置,它可能位于$ root中。


如果$refs.prospectsTable不起作用,請嘗試$root.$refs.prospectsTable。


也許這也應該是觀察者中的字符串,如下所示:


watch: {


   '$refs.prospectsTable.filteredItems': function (value) {

       console.log(value);

   }



}


查看完整回答
反對 回復 2021-04-08
  • 2 回答
  • 0 關注
  • 553 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號