vue3实战项目安装各种插件时候报错问题和解决


1.安装:npm install -D sass

注释: 多种安装方法
2.vue中局部引用,也可以设置全局css文件引入使用(使用场景全局的主题颜色更改等)

<style lang="scss" scoped>

overflow: hidden;溢出模块隐藏
visibility: hidden;隐藏全部

报错问题1.npm install失败,报错如下

https://www.baidu.com/s?ie=UTF-8&wd=npm%20ERR!%20Fix%20the%20upstream%20dependency%20conflict,%20or%20retry%20npm%20ERR!%20this%20command%20with%20–force,%20or%20–legacy-peer-deps%20npm%20ERR!%20to%20accept%20an%20incorrect%20(and%20potentially%20broken)%20dependency%20resolution.%20npm%20ERR!%20npm%20ERR!%20See%20D%3A%5Cnode%5Cnode_cache%5Ceresolve-report.txt%20for%20a%20full%20report.%20npm%20ERR!%20A%20complete%20log%20of%20this%20run%20can%20be%20found%20in%3A%20npm%20ERR!%20D%3A%5Cnode%5Cnode_cache%5C_logs%5C2023-03-03T04_20_57_593Z-debug-0.log

解决: npm install --legacy-peer-deps 即可成功安装 node_modules

报错问题2: vue3.0找不到模块“./App.vue”或其相应的类型声明

在这里插入图片描述
报错原因/解决:
因为 TypeScript 编译器无法识别 Vue 单文件组件 (.vue 文件) 的内容,要解决在随意一个xxxx.d.ts文件中添加配置,告诉 TypeScript 编译器,当它遇到 .vue 文件时,应该将其视为一个 Vue 组件,并导出一个默认的组件实例。

declare module '*.vue' {
    import type { DefineComponent } from 'vue'
    const component: DefineComponent<{}, {}, any>
    export default component
  }

在这里插入图片描述

引入使用echarts 相关

问题1. vue3中npm install echarts --save报错

npm WARN ERESOLVE overriding peer dependency npm WARN While resolving:
@element-plus/icons-vue@1.1.4 npm WARN Found: vue@3.0.0-beta.14 npm
WARN node_modules/vue npm WARN peer vue@“3.0.0-beta.14” from
@vue/compiler-sfc@3.0.0-beta.14 npm WARN
node_modules/@vue/compiler-sfc npm WARN peer
@vue/compiler-sfc@“^3.0.0-alpha.4” from vue-cli-plugin-vue-next@0.1.3
npm WARN node_modules/vue-cli-plugin-vue-next npm WARN 1 more
(the root project) npm WARN 5 more (vue-cli-plugin-vue-next,
vue-demi, …) npm WARN npm WARN Could not resolve dependency: npm
WARN peer vue@“^3.2.0” from @element-plus/icons-vue@1.1.4 npm WARN
node_modules/@element-plus/icons-vue npm WARN
@element-plus/icons-vue@“^1.1.4” from element-plus@2.2.2 npm WARN
node_modules/element-plus npm WARN npm WARN Conflicting peer
dependency: vue@3.2.47 npm WARN node_modules/vue npm WARN peer
vue@“^3.2.0” from @element-plus/icons-vue@1.1.4 npm WARN
node_modules/@element-plus/icons-vue npm WARN
@element-plus/icons-vue@“^1.1.4” from element-plus@2.2.2 npm WARN
node_modules/element-plus npm ERR! code ERESOLVE npm ERR! ERESOLVE
could not resolve npm ERR! npm ERR! While resolving:
@vue/eslint-config-typescript@5.0.2 npm ERR! Found:
eslint-plugin-vue@7.20.0 npm ERR! node_modules/eslint-plugin-vue npm
ERR! npm ERR! Could not resolve dependency: npm ERR! peer
eslint-plugin-vue@“^5.2.3 || ^6.0.0” from
@vue/eslint-config-typescript@5.0.2 npm ERR!
node_modules/@vue/eslint-config-typescript npm ERR! dev
@vue/eslint-config-typescript@“^5.0.2” from the root project npm ERR!
npm ERR! Conflicting peer dependency: eslint-plugin-vue@6.2.2 npm ERR!
node_modules/eslint-plugin-vue npm ERR! peer
eslint-plugin-vue@“^5.2.3 || ^6.0.0” from
@vue/eslint-config-typescript@5.0.2 npm ERR!
node_modules/@vue/eslint-config-typescript npm ERR! dev
@vue/eslint-config-typescript@“^5.0.2” from the root project npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this
command with --force, or --legacy-peer-deps npm ERR! to accept an
incorrect (and potentially broken) dependency resolution. npm ERR! npm
ERR! See D:\node\node_cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in: npm ERR!
D:\node\node_cache_logs\2023-03-03T04_29_35_204Z-debug-0.log

解决: npm install echarts --legacy-peer-deps
之后在App.vue中引入

import * as echarts from 'echarts'
import { provide } from 'vue'
 
export default {
  name: 'App',
  setup(){
    provide('echarts',echarts) 
  },
  components: {
  }
}

之后在新建echart.ts文件

import * as echarts from "echarts/core";

// 引入折线图、饼状图、柱状图
import { LineChart, PieChart, BarChart } from "echarts/charts";

// 引入提示框、标题、直角坐标系、数据集、内置数据转换器组件
import {
  TitleComponent,
  TooltipComponent,
  GridComponent,
  DatasetComponent,
  TransformComponent,
  LegendComponent,
} from "echarts/components";
// 标签自动布局,全局过渡动画等特性
import { LabelLayout, UniversalTransition } from "echarts/features";

echarts.use([LineChart, PieChart, BarChart, TitleComponent, TooltipComponent, GridComponent, DatasetComponent, TransformComponent, LegendComponent, LabelLayout, UniversalTransition]);

export default echarts;

引入使用

 <div id="main" style="width: 100%; height: 400px"></div>
import echarts from '../../utils/echart';
//注意这里引入了onMounted这个钩子,等会有用
import { onMounted, nextTick } from "vue";
export default {
  name: '',
  setup() {
    onMounted(() => {
      nextTick(() => {
        console.log(document.getElementById('hom_chart'))
        const myChart = echarts.init(document.getElementById('main'));
        myChart.setOption({
          title: {
            text: 'ECharts 入门示例'
          },
          tooltip: {},
          xAxis: {
            data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
          },
          yAxis: {},
          series: [
            {
              name: '销量',
              type: 'bar',
              data: [5, 20, 36, 10, 10, 20]
            }
          ]
        });

      })
    })
    return {
    }
  }

}

显示样式
在这里插入图片描述

但是这个地方有报提示,问题待解决…

在这里插入图片描述

3.开发遇到的问题

问题1: The template root requires exactly one element.eslint-plugin-vue报错

原因: 是安装的vetur扩展插件导致的,因为它有验证规则,提示开发者注意规范。但这个规范只适用vue2,所以插件是固定,还没有兼容vue3写法,但框架可能随时在更新。

解决 : 修改扩展插件验证规则,去掉vue3支持。
在这里插入图片描述
重新启动v-s-code就可以了

问题2. 模块 ““element-plus”” 没有导出的成员 “ElMessage”。你是想改用 “import ElMessage from “element-plus”” 吗?

Ts的配置文件,tsconfig.json

"moduleResolution": "Node"

关闭vscode重启就好了

问题3. element-puls组件全局更改成默认使用中文

element默认是中文,element plus默认使用的是英文,全剧更改正中文,如下操作
在这里插入图片描述
在这里插入图片描述
如果没有效果就关闭vscode,重新进就好了

待更新…

  • 19
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

大白菜1号

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

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

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

打赏作者

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

抵扣说明:

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

余额充值