Heim > Fragen und Antworten > Hauptteil
P粉7764125972023-08-27 00:16:54
您根本不需要 jQuery
。
应用程序 mounted()
/onMounted()
钩子将在所有组件安装完毕后运行。
请参阅下面的操场。
应用程序挂钩在最后运行。
查看有关 Lifecycle Hooks 和 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>