0
<template>
<div>
<transition name="fade" mode="out-in">
<div class="ui active inline loader" v-if="loading" key="loading"></div>
<div v-else key="loaded">
<span class="foo" ref="foo">the content I'm after is here</span>
</div>
</transition>
</div>
</template>
<script>
export default {
data() {
return {
loaded: false
}
},
mounted() {
setTimeout(() => { // simulate async operation
this.loaded = true
console.log($(this.$refs.foo).length, $(this.$el.find('.foo')).length)
}, 2000)
},
}
</script>
不管,如果我使用this.$refs
或this.$el
,我只能夠訪問裝載機DIV(<div class="ui active inline loader"/>
)。無法訪問由所示的元素V-如果零部件組裝回調
我該如何訪問元件安裝時不存在的元件?我必須將v-if
更改爲v-show
嗎?
看起來像你應該'看着'加載'。 –
@RoyJ嗯,在'loading'改變後如何改變執行代碼? – Johan
你究竟想要做什麼?如果'loading'爲'true',則不存在'foo'元素來訪問。內容是否存在於您的模板中而不是您的視圖模型中? –