使用vue cli4创建基础项目选择typescript,这样基本配置不用动
一、挂载Window的属性用法:在shims-vue.d.ts文件里加上:
declare interface Window { _hmt:any; //属性名:类型 }
二、项目引用百度地图:在shims-vue.d.ts文件里加上:
declare const BMap: any
三、在vue原型上挂载属性用法:在main.ts文件里加上:
注意事项,不能写在shims-vue.d.ts文件里,会和原有的返回vue冲突
declare module 'vue/types/vue' { interface Vue { route: Route; $store: Store; } }
四、js-cookie的引用,需要安装:
npm install js-cookie @types/js-cookie 两个,不然报错。
五、引用-微信js-sdk--目前没有@types版本,处理方法:
在src 目录下新建typings目录,新建weixin-js-sdk.d.ts文件
declare module 'weixin-js-sdk' { const content: any export = content }
在tsconfig.json文件里导入typings目录
include里加入"typings"
六、mixins注入问题
@Component({ mixins: [Emitter], })