久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

javascript - Vue $refs 為什么無(wú)法獲取組件對(duì)象

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

問(wèn)題描述

<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!這是為什么?

我在表格中渲染的按鈕,第一次點(diǎn)擊調(diào)用 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  為什么無(wú)法獲取組件對(duì)象

問(wèn)題解答

回答1:

可能你用v-if來(lái)切換組件展示,所以要在下一個(gè)tick才能獲取到

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

寫在

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

里試一下

回答3:

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

回答4:

調(diào)用這個(gè)方法this.$nextTick(function () {

// 里面打印 })

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 三门县| 湖口县| 龙岩市| 德保县| 饶河县| 莒南县| 淅川县| 大庆市| 西丰县| 金秀| 平果县| 五指山市| 德化县| 九龙县| 霍州市| 冕宁县| 山西省| 德兴市| 攀枝花市| 张掖市| 福鼎市| 十堰市| 平果县| 银川市| 武胜县| 阿拉尔市| 临西县| 辽宁省| 汝南县| 夏津县| 孝感市| 柘荣县| 丰台区| 石嘴山市| 宾阳县| 漳州市| 垫江县| 平阳县| 山阳县| 阳谷县| 云林县|