展开
拓展 关闭
订阅号推广码
GitHub
视频
公告栏 关闭

vue项目入口main.js配置

  • default
# 1.引入vue、根组件app
# 2.创建vue实例挂载到根组件
  • vue-cli + vue2
# 1.引入vue、根组件app
# 2.创建vue实例挂载到根组件
# 3.全局配置
Vue.prototype.$http = axios 
# 4.挂载到根组件
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

  • vue-cli + vue3
# 1.引入vue、根组件app
# 2.创建vue实例挂载到根组件
# 3.全局配置
app.config.globalProperties.$echarts = echarts
# 4.挂载到根组件
app.user(router)

  • vite2 + vue3
# 1.引入vue、根组件app
# 2.创建vue实例挂载到根组件
# 3.全局配置
app.config.globalProperties.$http=axios;
# 4.挂载到根组件
app.echarts=echarts

  • vue-cli + vue2 老版本写法
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import './assets/css/global.css'
// axios
import axios from 'axios'
// 默认url
axios.defaults.baseURL='http://localhost:8181'
// 全局配置
Vue.prototype.$http = axios 

Vue.config.productionTip = false
// 挂载router、store
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

  • vue-cli + vue3 新版本写法
import { createApp } from 'vue'
import App from './App.vue'

// 引入echarts
import * as echarts from 'echarts';

const app = createApp(App)
app.mount("#app")

// 全局配置
app.config.globalProperties.$echarts = echarts

  • vite2 + vue3 新版本写法
import { createApp } from 'vue'
import App from './App.vue'
import './index.css'
// element-plus
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
// 全局样式
import './static/css/global.css'
// router
import router from './route/index'
// axios
import axios from './static/js/axios';
// store
import store from './store/index'

const app =  createApp(App)
// 挂载
app.use(ElementPlus)
app.use(router)
app.use(store)
app.mount('#app')

// 全局配置
app.config.globalProperties.$http=axios;

  • vite2 + vue3
import { createApp } from 'vue'
import App from './App.vue'
import * as echarts from 'echarts'
 
const app = createApp(App).mount('#app')
// 挂载
app.echarts=echarts

posted @ 2021-12-13 09:38  DogLeftover  阅读(117)  评论(0编辑  收藏  举报