behaviors
发布于 5 年前 作者 mingtian 10394 次浏览 来自 问答

这是好东西,意味着组件能mixin了,

那为啥不赶紧提供一个面向page的behaviors啊!!!!

10 回复

多谢耐心解答

但是目前问题如下:

  1. page直接用Component声明,

    Component({
      behaviors: [myBehavior],
      properties: {
        myProperty: {
          type: String
        }
      },
      data: {
        myData: {}
      },
      attached: function(){},
      methods: {
        myMethod: function(){}
      }
    })
    报错:

pages/fenxiao/stores/index.js 出现脚本错误或者未正确调用 Page()

(anonymous) @ appservice:15026

WAService.js:3 jsEnginScriptError

n is not a function

TypeError: n is not a function

    at _ (http://127.0.0.1:9973/appservice/__dev__/WAService.js:12:14247)

    at Function.y [as create] (http://127.0.0.1:9973/appservice/__dev__/WAService.js:12:14400)

    at Function.p.prepare (http://127.0.0.1:9973/appservice/__dev__/WAService.js:11:12109)

    at F (http://127.0.0.1:9973/appservice/__dev__/WAService.js:13:14230)

    at W (http://127.0.0.1:9973/appservice/__dev__/WAService.js:13:14261)

    at U (http://127.0.0.1:9973/appservice/__dev__/WAService.js:13:14641)

    at Function.<anonymous> (http://127.0.0.1:9973/appservice/__dev__/WAService.js:13:17012)

    at http://127.0.0.1:9973/appservice/__dev__/WAService.js:13:22046

    at http://127.0.0.1:9973/appservice/__dev__/WAService.js:5:22487

    at Array.forEach (<anonymous>)

  1. 还是上述写法,在 json文件里写 : usingComponent: true, 这次没这么多异常了,但是提示:

Page[pages/fenxiao/stores/index] not found. May be caused by: 1. Forgot to add page route in app.json. 2. Invoking Page() in async task.

用第一种写法,忽略掉那个错误即可。

写在 methods 定义段中即可。

其实页面也可以用Component构造器定义的。但是目前会报个错“出现脚本错误或者未正确调用 Page()”,你可以先忽略。

好吧,回头再试试

那你还是稍等吧。我们之后会支持的。

怎么试都不行

不管onload写到哪里一样还是报错呢?。。。

而且onLoad里面不执行

可否给个例子?

不胜感激

Q:我现在能用在实际项目不?

A:我们需要最后确定下,请关注近期的更新。你可以先用着。

Q:给个page用component声明的例子?

A:就像Component()那样用就可以了。

Q:Forgot to add page route in app.json

A:虽然你用的是Component(),但要记得把它加到app.json的pages列表中去。

Page[pages/fenxiao/stores/index] not found. May be caused by: 1. Forgot to add page route in app.json. 2. Invoking Page() in async task.

用Component写直接给这个。。。。

回到顶部