Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

项目中自己封装了插件,如果在 App() 中调用插件方法呢? #30

Closed
baranwang opened this issue Mar 20, 2019 · 4 comments

Comments

@baranwang
Copy link
Contributor

baranwang commented Mar 20, 2019

现在 App() 貌似不在 tina 中,如何在 App() 调用封装的插件方法呢?

@imyelo
Copy link
Member

imyelo commented Mar 20, 2019

前阵子刚好加了 App,刚刚发布,是你需要的功能吗?

npm i --save @tinajs/tina@^1.6.0

API: https://tina.js.org/#/api/README?id=app

@baranwang
Copy link
Contributor Author

对的!太及时了!

@baranwang
Copy link
Contributor Author

插件在 App() 中应该怎么使用呢?

export function mixin() {
 function setup() {
   this.$request = request
   this.$login = login
   this.$loading = loading
 }
 return {
   beforeLoad: setup,
   created: setup,
 }
}

const Plugin = {
 install({ App, Page, Component }) {
   App.mixin(mixin())
   Page.mixin(mixin())
   Component.mixin(mixin())
 },
}

export default Plugin

这样的写法在 App() 中调用

App.define({
  onLaunch() {
    this.$login()
  }
})

提示this.$login is not a function;at App lifeCycleMethod onLaunch function

@imyelo
Copy link
Member

imyelo commented Mar 20, 2019

export function mixin() {
 function setup() {
   this.$request = request
   this.$login = login
   this.$loading = loading
 }
 return {
+   onLaunch: setup,
   beforeLoad: setup,
   created: setup,
 }
}

这样呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants