让App组件归Vue/React管
Vue2
//main.js中
//导入Vue核心包
import Vue from 'vue'
//导入App组件
import App from './App.vue'
//当前处于什么环节下(true:开发环境; false:生产环境)
Vue.config.productionTip = false
//Vue实例化
//提供了render方法,基于App.vue创建结构,渲染index.html
//即,将App挂载到index.html中的 <div id="app"></div>
//写法一:
new Vue({
render: h => h(App),
}).$mount('#app')
//写法二:
new Vue({
el:'#app',
render: h => h(App),
})
//render:h => h(App)
render:(createElement)=>{
return createElement(App)
}
Vue3
//main.js
//通过createApp() 创建Vue实例
//将Vue2的 new Vue() 进行了封装:createApp()
const app = createApp(App)
//将app挂载到index.html中的 <div id="app"></div>
app.mount('#app')
React
//index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
//通过react-dom将App挂载到 html中的root节点上
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
//严格模式:存不存在都无所谓
<React.StrictMode>
<App />
</React.StrictMode>
);