首页 技术 正文
技术 2022年11月15日
0 收藏 603 点赞 2,529 浏览 1660 个字

开发前提:

1、在微信公众平台注册申请 AppID

2、安装开发者工具https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html

框架部署:

1、vue-cli 创建 mpvue,参考 http://mpvue.com/mpvue/quickstart.html

2、配置 Typescript

# 安装 vue 与装饰器,mpvue-loader目前支持用TypeScript来写,功能还在完善中(WIP)。需要搭 配vue-property-decorator来使用。
$ npm install --save vue vue-property-decorator
# 安装 typescript
$ npm install --save typescript@3.3.3333
# 安装 typescript 所需loader(注意存在版本兼容问题,需下载指定版本ts-loader与awesome-typescript-loader最新版目前不兼容webpack4以下版本)
$ npm install --save ts-loader@3.1.1 awesome-typescript-loader@4.0.1
# 安装声明文件@types/node @types/weixin-app
$ npm install --save @types/node @types/weixin-app

微信小程序框架部署:mpvue+typescript

3、安装官方微信小程序定义文件:npm install miniprogram-api-typings

4、配置webpack,参考 http://mpvue.com/build/mpvue-loader.html

微信小程序框架部署:mpvue+typescript

注:若找不到 webpack.conf.js 则对应找 webpack.base.conf.js,

    在第 7 步未做之前不要修改把 pages 里的 main.js 文件删掉!!

5、让TypeScript识别Vue文件:

TypeScript识别不了后缀为vue的文件,需要加入一个声明文件,

在项目的src目录下新建一个名为vue-shim.d.ts的文件,在其中增加代码

declare module "*.vue" {
import Vue from "vue";
export default Vue;
}

6、增加TypeScript配置:在项目根目录下新建一个名为 tsconfig.json 的文件,增加内容

{
"compilerOptions": {
// 与 Vue 的浏览器支持保持一致
"target": "es2015",
// 这可以对 `this` 上的数据属性进行更严格的推断
"strict": true,
// 如果使用 webpack 2+ 或 rollup,可以利用 tree-shake:
"module": "es2015",
"moduleResolution": "node",
"baseUrl": "./",
"outDir": "./dist/",
"paths": {
"vue": [
"node_modules/mpvue"
],
"@/*": [
"src/*"
]
},
"types": [
"@types/weixin-app", //声明文件
"@types/node"
],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"skipLibCheck": true,
"strictPropertyInitialization": false,
"experimentalDecorators": true
},
"include": [
"./src/**/*"
],
"exclude": [
"node_modules"
],
"typeAcquisition": {
"enable": true
}
}

注:完整可看 https://www.tslang.cn/docs/handbook/tsconfig-json.html

7、配置完main.ts后需要将webpack.conf.js中的配置入口文件后缀改为.ts

微信小程序框架部署:mpvue+typescript

最终生成目录:

微信小程序框架部署:mpvue+typescript

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918