P粉7764125972023-08-27 00:16:54
You don't need jQuery
at all.
Application mounted()
/onMounted()
The hook will run after all components have been mounted.
See playground below.
Application hooks run at the end.
See more about Lifecycle Hooks and onMounted()
const { createApp, onMounted } = Vue const Comp = { props: ['num'], setup(props) { onMounted(() => { console.log(`Comp[${props.num}]: onMounted(): from setup()`)} ); }, mounted() { console.log(`Comp[${this.num}]: mounted(): from Options API`) } } const App = { components: { Comp }, setup() { onMounted(() => { console.log("onMounted(): from setup()")} ); }, mounted() { console.log("mounted(): from Options API") } } const app = createApp(App) app.mount('#app')
#app { line-height: 1.75; } [v-cloak] { display: none; }
<div id="app" v-cloak> <comp v-for="n in 100" :key="n" :num="n"></comp> </div> <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>