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>