vue-cli3引入第三方的js依赖包并使用其方法

注意:引入第三方的包有两种,一种是做特殊要求必须如何引用的;一种是没有要求的

情况1:js包要求了如何引入的,按照其文档的方式引入和使用即可

1.1直接在indes.html按照要求引入
在这里插入图片描述

1.2使用方法
在这里插入图片描述

情况2:没有声明如何引入的

2.1直接在index.html下

<script src="<%= BASE_URL %>某某某包.js"></script>

需要注意的是,如果用到js包里面的方法,则需要将其函数方法暴露出来

在这里插入图片描述

2.2在组件内使用初始化方法,注意引入方式;

在这里插入图片描述

可参考链接:
https://blog.csdn.net/weixin_34006468/article/details/88687199?utm_medium=distribute.pc_feed_404.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_feed_404.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecas

https://www.cnblogs.com/aidixie/p/10649725.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在Vue-cli 3中使用TypeScript,需要先安装TypeScript和Vue的TypeScript声明文件。 1. 安装TypeScript和Vue TypeScript声明文件: ``` npm install typescript vue-class-component vue-property-decorator --save-dev npm install @types/node @types/webpack @types/vue @types/vue-router @types/vuex --save-dev ``` 2. 在项目根目录下创建一个`tsconfig.json`文件,用于配置TypeScript编译器的选项: ``` { "compilerOptions": { "target": "esnext", "module": "esnext", "strict": true, "jsx": "preserve", "moduleResolution": "node", "experimentalDecorators": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "noImplicitReturns": true, "noImplicitThis": true, "noImplicitAny": false, "suppressImplicitAnyIndexErrors": true, "sourceMap": true, "baseUrl": ".", "paths": { "@/*": [ "src/*" ] } }, "include": [ "src/**/*.ts", "src/**/*.tsx", "tests/**/*.ts", "tests/**/*.tsx" ], "exclude": [ "node_modules" ] } ``` 这里的配置项可以根据你的需求进行调整。 3. 修改项目的入口文件`main.js`,将其改为`main.ts`,并且使用`Vue.extend`来定义Vue组件: ``` import Vue from 'vue' import App from './App.vue' Vue.config.productionTip = false new Vue({ render: h => h(App), }).$mount('#app') ``` 4. 在`src`目录下创建一个`shims-tsx.d.ts`文件,用于声明Vue组件的类型: ``` declare global { namespace JSX { // tslint:disable no-empty-interface interface Element extends Vue.VNode {} // tslint:disable no-empty-interface interface ElementClass extends Vue {} interface IntrinsicElements { [elem: string]: any; } } } ``` 5. 在`src`目录下创建一个`shims-vue.d.ts`文件,用于声明Vue组件的类型: ``` declare module '*.vue' { import Vue from 'vue'; export default Vue; } ``` 6. 修改`package.json`文件,将`main.js`改为`main.ts`: ``` { "name": "my-app", "version": "0.1.0", "private": true, "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint" }, "dependencies": { "vue": "^2.6.10", "vue-router": "^3.0.3", "vuex": "^3.0.1" }, "devDependencies": { "@types/node": "^10.12.18", "@types/vue": "^2.0.8", "@types/vue-router": "^3.0.2", "@types/vuex": "^3.0.0", "typescript": "^3.3.3333", "vue-class-component": "^6.0.0", "vue-property-decorator": "^7.0.0", "vue-template-compiler": "^2.6.10" }, "main": "src/main.ts", "browserslist": [ "> 1%", "last 2 versions" ] } ``` 7. 运行`npm run serve`命令来启动开发服务器,开始使用TypeScript进行Vue开发。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值