• vue3-搭建项目-vue2-vu3使用上的变化


    见文档https://vue-docs-next-zh-cn.netlify.app/guide/installation.html#%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%B7%A5%E5%85%B7-cli

    vite搭建:

    1. 安装vite   npm init @vitejs/app
    2. npm init vite <project-name>
    3. cd <project-name>
    4. npm i
    5. npm run dev

      vite引入组件时需要加文件后缀不然报错

    路由配置

      下载路由: npm install vue-router@4

      1. 新建router文件夹,其下建index.js

    import {createRouter, createWebHashHistory, createWebHistory} from "vue-router"
    const routes = [
        { 
            path: "/",
            component: () => import('../components/home.vue')
        },
        { 
            path: "/about", 
            component: () => import('../components/pages/about.vue')
        },
    ];
    
    const router = createRouter({
        // 4. 采用hash 模式
        history: createWebHashHistory(),
        // 采用 history 模式 history: createWebHistory(),
        routes, 
    });
    export default router

      

      2. 挂载到main.js

    import { createApp } from 'vue'
    import App from './App.vue'
    import router from './router/index'
    
    // createApp(App).mount('#app')
    const app = createApp(App)
    app.use(router)
    app.mount('#app')

    1. 调用挂在vue实例区别

    //vue2
    //main.js全局引入
    import axios from 'axios'
    Vue.prototype.$axios = axios
    //在组件中使用通过this.$axios调用
    //vue3
    //main.js
    import axios from 'axios'
    import * as echarts from 'echarts'
    app.config.globalProperties.$http = axios
    app.config.globalProperties.$echarts = echarts
    
    //再别的组件中使用
    const { proxy } = getCurrentInstance()
    let chart1 = proxy.$echarts.init(chartDom);
  • 相关阅读:
    第02组 Beta冲刺(1/4)
    第02组 Alpha事后诸葛亮
    第02组 Alpha冲刺(4/4)
    第02组 Alpha冲刺(3/4)
    团队作业6——复审与事后分析(集合贴)
    事后诸葛亮分析报告
    Alpha阶段项目复审
    团队作业5——测试与发布(Alpha版本)
    团队作业四——七天的敏捷冲刺日志集合贴
    第 7 篇 Scrum 冲刺博客
  • 原文地址:https://www.cnblogs.com/xhrr/p/15176820.html
Copyright © 2020-2023  润新知