Giter Club home page Giter Club logo

mpvue-ts-demo's Introduction

mpvue Typescript demo

A mpvue project with Typescript

已支持mpvue 2.0 (微信小程序、百度智能小程序、头条小程序、支付宝小程序)

1.x版本的请前往v1分支

Build Setup

# install dependencies
yarn

# serve with hot reload at localhost:7100
yarn run dev

# build for production with minification
yarn run build

# build for production and view the bundle analyzer report
yarn run build --report

mpvue

mpvue-ts-demo's People

Contributors

diyews avatar huang-jinxian avatar winggao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mpvue-ts-demo's Issues

Cannot read property 'template' of undefined

上周我直接clone下来执行npm run dev完全没有问题,只有执行npm run build时有问题。
这周再来就抛异常了。

H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\mpvue-loader\lib\mp-compiler\util.js:19
  const filePath = `/${resolveSrc(context, file)}.${fileExt.template}`
                                                            ^
TypeError: Cannot read property 'template' of undefined
    at getCompInfo (H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\mpvue-loader\lib\mp-compiler\util.js:19:61)
    at createPageMPML (H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\mpvue-loader\lib\mp-compiler\index.js:41:30)
    at resolve (H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\mpvue-loader\lib\mp-compiler\index.js:196:9)
    at onResolve (H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\enhanced-resolve\lib\Resolver.js:70:11)
    at innerCallback (H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\enhanced-resolve\lib\Resolver.js:130:22)
    at callbackWrapper (H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\enhanced-resolve\lib\createInnerCallback.js:10:21)
    at H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\tapable\lib\Tapable.js:347:15
    at H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\enhanced-resolve\lib\UnsafeCachePlugin.js:39:22
    at callbackWrapper (H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\enhanced-resolve\lib\createInnerCallback.js:10:21)
    at innerCallback (H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\enhanced-resolve\lib\Resolver.js:130:22)
    at callbackWrapper (H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\enhanced-resolve\lib\createInnerCallback.js:10:21)
    at H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\tapable\lib\Tapable.js:347:15
    at innerCallback (H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\enhanced-resolve\lib\Resolver.js:130:22)
    at callbackWrapper (H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\enhanced-resolve\lib\createInnerCallback.js:10:21)
    at H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\tapable\lib\Tapable.js:347:15
    at resolver.doResolve.createInnerCallback (H:\okou\versionControl\git\mpvue-ts-demo2\node_modules\enhanced-resolve\lib\DescriptionFilePlugin.js:41:24)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `cross-env node build/dev-server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

mac上报错

ERROR Failed to compile with 7 errors

Module build failed: Error: No ESLint configuration found.

module "common/manifest.js" is not defined

删除demo, 重新下载,再解压
npm i
npm run dev
后以下错误:
VM277:1 thirdScriptError
sdk uncaught third Error
module "common/manifest.js" is not defined
Error: module "common/manifest.js" is not defined
at require (http://127.0.0.1:61404/appservice/__dev__/WAService.js:23:13423)
at http://127.0.0.1:61404/appservice/__dev__/WAService.js:23:13171
at http://127.0.0.1:61404/appservice/pages/index/main.js:3:1
at require (http://127.0.0.1:61404/appservice/__dev__/WAService.js:23:13564)
at :6:7
at HTMLScriptElement.scriptLoaded (http://127.0.0.1:61404/appservice/appservice?t=1539488179497:1190:23)

出现脚本错误或者未正确调用 Page()

你好,请问一下,为什么我通过<script lang="ts" src="./XXXXX.ts"></script> 这种方式引入 ts 文件之后会导致整个小程序编译完成之后无法运行呢,在控制台会有错误提示:出现脚本错误或者未正确调用 Page()。

感谢!能否说明一下需要做哪些更改?

感谢您提供的Typescript项目!
我想按照您提供的例子将一个刚生成的mpvue项目加入typescript支持,整个过程很不顺利……
能否大概说一下您在加入ts支持的时候做了哪些事情?我看到的有:

  1. 在.vue 的<script> 里面加上lang="ts"
  2. 在view-loader.conf.js里面加入ts: [... 部分
  3. 在webpack.base.conf.js里面加入test: /.tsx?$/, 部分
  4. 加入vue-shim.d.ts
  5. 加入tsconfig.json
  6. package.json里面加入typescript

但是现在我尝试把一个page变成ts的page,结果是dist/目录里面没有这个page了...
.ts文件里面也对Component和Vue报错

启动 报错

Error: Cannot find module 'E:\mpvue-ts-demo$NODE_DEBUG_OPTION'

package.json中依赖版本过旧

目前这个模板里面webpack版本很老,mpvue目前也更新到了2.0
请问这个模板可以更新下依赖吗?
自己太菜,根据模板升级出现了好多好多奇奇怪怪的问题,
请作者大大更新一下到最新版本好么?

mpType注入问题

基于这个项目把之前的mpvue项目整体移植到typescript,基本过程很顺利,唯一有一个地方:

mpType怎么注入?

我看到这个demo里面两个地方做了处理:
在最外面的main.ts
https://github.com/WingGao/mpvue-ts-demo/blob/dev/src/main.ts

interface IMpVue extends VueConstructor {
  mpType: string
}

// ...Other code...

// 在这个地方引入是为了registerHooks先执行
const MyApp = require('./App.vue').default as IMpVue

和app.ts
https://github.com/WingGao/mpvue-ts-demo/blob/dev/src/app.ts

// 必须使用装饰器的方式来指定components
@Component({
  mpType: 'app', // mpvue特定
}as any)
class App extends Vue {

我理解main.ts应该是之前的尝试失败了忘了删掉?
有用的是app.ts里面的这个,如果没有的话app的微信事件onLaunch啥的都没有

但是我发现这样的副作用是这样的:
如果在Page里面做同样的事情:

@Component({
  components: { HelloWorld },
  mpType: 'page'
} as any)
export default class Page extends Vue {

结局是自定义组件(HelloWorld)没有注册上!页面上渲染不出来

问题出在 as any 上, 比如这样也是不行的:

@Component({
  components: { HelloWorld }
} as any)
export default class Page extends Vue {

但是如果没有as any的话(可能你也试过)ts编译不过……

目前问题貌似不是很大,因为看了mpvue的代码如果没有定义mpType的话默认是‘page’
但是正确的解法是什么呢?比如还有一个mpType是‘component’ 到时候就麻烦了……

(写了一个多星期的JS完全崩溃了,没有compiler写出来全是runtime error,前端的大佬们都是什么样的存在……)

main.ts 引入 less 问题

import '@/weui/weui.css'
import '@/weui/weui_theme.less'
// 引入 less 文件报错
To install it, you can run: npm install --save @/weui/weui_theme.less

export default class Index extends VueClass dada 数据可以继承 function 方法不能继承

export default class VueClass extends Vue {
  public ver: number = 123

  public testFun (): any {
    console.log('testFun', 123456)
  }

  public onShareAppMessage (options?: any): any {
    // let _this = this
    let shareObj = {
      title: '',
      path: '', 
      imgUrl: '', 
      success: function (res: any) {
        // 转发成功之后的回调
        if (res.errMsg === 'shareAppMessage:ok') {
        }
      },
      fail: function (res: any) {
        // 转发失败之后的回调
        // 用户取消转发
        if (res.errMsg === 'shareAppMessage:fail cancel') {
        // 转发失败,其中 detail message 为详细失败信息
        } else if (res.errMsg === 'shareAppMessage:fail') {
        }
      }
    }
    return shareObj
  }
}

// 分享 功能无效 this.testFun() 报错 is not a function
export default class Index extends VueClass {
  AppUrls = AppUrls

  onShow() { // 小程序 hook
    // this.testFun()
    debug('onShow')
  }

  mounted() { // vue hook
    debug('mounted')
  }
}

不能使用components

代码如下:
image

结果如下:
image

组件对应的生命周期都触发了,但是在Wxml节点里不渲染

Gao兄,如何在mpvue里面支持第三方的插件呢?

由于业务需求中需要用到知晓云的SDK,但是在app.ts中加入的时候还是报错的,在mpvue上廋了一下没找到版本,不知道Gao兄能否指导一下,感谢。
image
因为他是是需要这点,但是我初始化的他找不到wx.BaaS = requirePlugin('sdkPlugin'),不知道怎么解决

Reflect.getMetadata is not a function

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.