vue3.0+Vue/Cli 4.5.0 项目搭建

npm@6.13.4

1.初见vue3.0项目

node v12.14.1
npm 6.13.4
vue/cli 4.5.0

全局安装 vue/cli
npm安装

npm i -g @vue/cli

yarn安装

yarn global add @vue/cli

创建vue 项目

vue create datav-project

手动配置

vue3.0

进入项目

cd datav-project

!注意:增加typeScript vue-router vue-store 都是ts版本

添加 TypeScript

vue add typescript   // 重新启动 才能看到效果
//cli 添加 typeScript   

Use class-style component syntax? (Y/n),
//?使用类样式的组件语法?(y/n),
参考.
Use Babel alongside TypeScript (required for modern mode,auto-detected polyfills,transpiling JSx)? (V/n)】
// 在使用Babel的同时使用TypeScript(现代模式需要,自动检测的填充,transpiling JSx)
// Convert all .js files to .ts // 全部js转ts
// Allow .js files to be compiled? // 允许js 完成编译
// Skip type checking of all declaration files (recommended for apps) // 跳过文件检测

增加 router

vue add router   // 重新启动 才能看到效果

增加 vuex

vue add vuex   // 重新启动 才能看到效果

增加 axios

vue add axios  // 重新启动 才能看到效果

axios引入

import axios from 'axios'
 
import VueAxios from 'vue-axios'
 
createApp(App).use(VueAxios, axios)

axios 挂载原理

//   Vue.axios = _axios;
//   window.axios = _axios;
//   Object.defineProperties(Vue.prototype, {
//     axios: {
//       get() {
//         return _axios;
//       },
//     },
//     $axios: {
//       get() {
//         return _axios;
//       },
//     },
//   });

axios 的使用

vue.axios.get(api).then((response) => {
    console.log(response.data)
})
this.axios.get(api).then((response) => { 
    console.log (response.data)
})
this.$http.get(api).then((response) =>{
    console.log( response.data)

下载scss

npm install -D sass-loader node-sass

版本
"sass": "^1.38.0",
 
"node-sass": "^6.0.1",
"sass-loader": "^8.0.2",

引入第三方库

npm install @jiaminghi/data-view
// 将自动注册所有组件为全局组件
import dataV from '@jiaminghi/data-view'

Vue.use(dataV)
// 按需引入
import { borderBox1 } from '@jiaminghi/data-view'

Vue.use(borderBox1)

vue2.0的版本 不兼容

Could not find a declaration file for module '@jiaminghi/data-view'.

方案一

npm i --save-dev @types/jiaminghi__data-view

方案二
在这里插入图片描述
在 shims-vue.d.ts中增加

declare module '@jiaminghi/data-view'
  "vue-class-component": "^7.2.3",  // 官方核心库 vue 3.0
  "vue-property-decorator": "^9.1.2",  // 非官方开发核心库

----------------------------------------------------------------

自动配置

router vuex scss

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

web修理工

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值