P粉4045397322023-08-26 14:57:42
您可以直接在mounted()
鉤子中將非響應式屬性附加到元件實例上:
<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>