更新了微信后,(微信版本6.6.1)自定义组件绑定事件出现错误
发布于 6 年前 作者 na97 11956 次浏览 来自 问答

vas-userinfo是我定义的一个组件,之前小程序上线了,是没有错误的,后来微信版本升级后,就报错了,我把这行代码注释之后就不会报错。(安卓版报同样的错)

<vas-userinfo mode=‘simple’ bindtap=‘toPersonal’></vas-userinfo>

错误如下:

9 回复

mode: String = ‘simple’ 还有这种写法?

mode: {
  type: String,
  value: 'simple'
}

mode: String = ‘simple’

这个写法在任何版本上都会出错的,会把js的内置类替换掉,导致各种各样的小程序bug。应该使用5楼的写法。

properties: {

    mode:String,

    showIndicator:Boolean

},

改成这样就开发者工具、真机都可以,是不能设置value了吗

你好,我们需要更多细节以便定位问题。能否提供一下自定义组件js文件的属性定义?

以前是可以的呀,再者,我刚使用

mode: {
  type: String,
  value: 'simple'
}

这种,连开发者工具都报错了

一样会报错呀,连开发者工具都报错了,

代码如下:

properties: {

    mode:{

        type:String,

        value:‘simple’

    },

    showIndicator:{

        type:Boolean,

    value:false

    }    

},

报错信息:

WAService.js:3 jsEnginScriptError

String is not a function

TypeError: String is not a function

    at v (http://127.0.0.1:9973/appservice/__dev__/WAService.js:12:14944)

    at e.protoFunc.<anonymous> (http://127.0.0.1:9973/appservice/__dev__/WAService.js:12:15439)

    at a.doUpdates (http://127.0.0.1:9973/appservice/__dev__/WAService.js:11:28835)

    at t.applyProperties (http://127.0.0.1:9973/appservice/__dev__/WAService.js:14:640)

    at e.value (http://127.0.0.1:9973/appservice/__dev__/WAService.js:13:26403)

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

    at Array.forEach (<anonymous>)

    at e.value (http://127.0.0.1:9973/appservice/__dev__/WAService.js:13:26447)

    at e.value (http://127.0.0.1:9973/appservice/__dev__/WAService.js:13:23357)

    at Object.p.create [as createElement] (http://127.0.0.1:9973/appservice/__dev__/WAService.js:12:21061)

你的代码是不是还有哪里把 String 对象给改了?

// components/vas-userinfo.js

const { profile } = require(’…/…/libs/profile.js’);

Component({

/**

  * 组件的属性列表

  */

properties: {

mode: String = ‘simple’, // ‘simple’ or ‘detail’

showIndicator: Boolean = false

},

/**

  * 组件的初始数据

  */

data: {

userInfo: {}

},

attached: function() {

if(profile.validate()) {

this.setData({

userInfo: profile.userinfo

})

}

},

/**

  * 组件的方法列表

  */

methods: {

}

})

回到顶部