您可以直接在mounted()
鉤子中將非響應(yīng)式屬性附加到元件實(shí)例上:
<script> export default { // tooltip: null, mounted() { // this.$options.tooltip = new Tooltip(...) this.tooltip = new Tooltip(...) }, } </script> <template> <!-- BEFORE --> <i @mouseover="hover = true; $options.tooltip.show();" @mouseleave="hover = false; $options.tooltip.hide();" @click="$options.tooltip.hide();" ref="icon" /> <!-- AFTER --> <i @mouseover="hover = true; tooltip.show();" @mouseleave="hover = false; tooltip.hide();" @click="tooltip.hide();" ref="icon" /> </template>