Closed ljjsimon closed 3 years ago
试了下版本 >=2.0.0 是有支持的。怀疑有问题的话就给个代码片段?
@LastLeaf 就上面这个代码啊。。。我console.log(this.data.a)输出是undefinedbar
@LastLeaf 我是2.2.0
我用你的代码 + v2.2.0 试了下,在 wxml 数据绑定里面显示完全正常。
有问题的话请提供完整代码片段。
难道是我见鬼了不成? package.json
{
"name": "weapp",
"version": "1.0.0",
"description": "这是云开发的快速启动指引,其中演示了如何上手使用云开发的三大基础能力:",
"main": "index.js",
"dependencies": {
"@vant/weapp": "^1.6.6",
"miniprogram-computed": "^4.0.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
index.js
const computedBehavior = require('miniprogram-computed')
Page({
behaviors: [computedBehavior],
/**
* 页面的初始数据
*/
data: {
url:''
},
computed:{
a(data){
return data.b+'bar'
},
b(data){
return 'foo'
}
}
})
index.wxml
<view style="margin-top:100px;">{{a}}</view>
这段代码里面写的是 "miniprogram-computed": "^4.0.1"
,然而 v4 的接口变了,下面的 const computedBehavior = require('miniprogram-computed')
调用会失效。
麻烦看下更改版本之后有没有 npm install 和点击开发者工具中的“工具 > 构建 npm ”。
@LastLeaf 可以了,谢谢。之前是2.2.0,版本和代码都是从小程序文档复制过来的https://developers.weixin.qq.com/miniprogram/dev/extended/utils/computed.html。 今天早上升级后没有构建,刚构建完就好了
有可能是以前也忘了构建。我试过 v2.2.0 也是 ok 的。但是 v1 不行。
比如 computed:{ a(data){ return data.b+'bar' }, b(data){ return 'foo' } }