国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

javascript - Vue $refs 為什么無法獲取組件對象

瀏覽:119日期:2023-03-16 11:21:25

問題描述

<el-tree ref='permissions_tree' :data='permissions' :props='basicConfig.defaultProps' show-checkbox node-key='id' :render-content='renderNode'></el-tree>

mounted () { console.log(this.$refs.permissions_tree);}

在 mounted 中打印輸出的是undefined!這是為什么?

我在表格中渲染的按鈕,第一次點擊調用 console.log(this.$refs.permissions_tree);得到的也是 undefined,第二次就能正常獲取到組件了

{ title: ’操作’, key: ’action’, align: ’center’, render: (h, params) => { return h(’p’, [h(’Button’, { props: { type: ’primary’, size: ’small’ }, style: { marginRight: ’5px’ }, on: { click: () => { this.userForm.staffid = params.row.staffid; this.userForm.name = params.row.name; this.userForm.phoneticize = params.row.phoneticize; this.userForm.gender = params.row.gender; this.userForm.mobile = params.row.mobile; this.userForm.telephone = params.row.telephone; this.userForm.identification = params.row.identification; this.userForm.positions = params.row.positions; this.userForm.permissions = params.row.permissions; this.userFormShow = true; console.log(this.$refs.permissions_tree); //這里 } }}, ’編輯’) ]); }}

javascript - Vue $refs  為什么無法獲取組件對象

問題解答

回答1:

可能你用v-if來切換組件展示,所以要在下一個tick才能獲取到

this.$nextTick(() => { console.log(this.$refs.permissions_tree);});回答2:

寫在

this.$nextTick(() => {})

里試一下

回答3:

外層組件是不是使用了v-if,換成v-show 試一下

回答4:

調用這個方法this.$nextTick(function () {

// 里面打印 })

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 阿坝县| 永吉县| 西安市| 酒泉市| 福泉市| 宁南县| 师宗县| 孟州市| 荥阳市| 新疆| 吕梁市| 西城区| 曲阳县| 山东省| 晋江市| 汉寿县| 绍兴市| 政和县| 河南省| 桦南县| 永寿县| 忻城县| 盖州市| 康乐县| 渑池县| 中卫市| 鄂州市| 石楼县| 土默特左旗| 家居| 淮北市| 道真| 台湾省| 莎车县| 马山县| 周至县| 河间市| 屯门区| 涿鹿县| 安吉县| 科尔|