<template>
<component-to-re-render :key="reloadMe" />
</template>
<script>
export default {
data() {
return {
reloadMe: 0,
}
};
methods: {
forceRerender() { this.reloadMe += 1; }
}
}
</script>
Vue2 中自定义
// Utils
import Utils from './utils/utils.js'
// Init Global Utils
Vue.prototype.$utils = Utils
在 Vue3 中
// Utils
import Utils from './utils/utils.js' // <-- import file
const app = createApp(App)
// Init Global Utils
app.config.globalProperties.$utils = Utils // <-- set globally
app.mount('#app')
现在我们可以通过简单地使用以下内容在任何地方访问我们的实用程序方法:
// In template
$utils.copyToClipboard(text)
// In methods
this.$utils.copyToClipboard(text)