uni-app项目笔记

获取时间戳

var timestamp = new Date().getTime()

引号中访问属性

<uni-collapse v-for="(request, index) in requestList">
    <uni-collapse-item :title="'请求'+index">
    </uni-collapse-item>
</uni-collapse>

数据库查询

const db = uniCloud.database()
// 以user表为例
db.collection('user').get().then((res)=>{
    // 数据对象数组res.result.data
}).catch((err)=>{
    console.log(err.code)
	console.log(err.message)
})

// 加上where
db.collection('user').where({name: '...'}).get().then((res)=>{
    // 数据操作
    // 如果只有一个数据,那么为res.result.data[0]
}).catch((err)=>{
    console.log(err.code)
	console.log(err.message)
})

这里面的this是可以指Vue实例的,所以是可以直接访问和修改data数据

数据库添加

const db = uniCloud.database()
db.collection('user').add({
    name: this.username,
    password: this.password,
}).then((res)=>{
    // 数据操作
}).catch((err)=>{
    console.log(err.code)
	console.log(err.message)
})

数据库删除

const db = uniCloud.database()
db.collection('user').where({
    name: username
}).remove().then((res)=>{
    uni.showToast({
        title: '用户删除成功',
        icon: 'success'
    })
}).catch((err)=>{
    console.log(err.code)
	console.log(err.message)
})

数据库更新

const db = uniCloud.database()
db.collection('user').where({
    name: username
}).update({
    age: 20
}).catch((err)=>{
    console.log(err.code)
	console.log(err.message)
})

刷新当前页面

1.利用路由,强制刷新当前页面
setTimeout(()=>{
    this.$router.go(0)
}, 500)
2.重定向到本页面
uni.redirectTo({
    url: ''
})
前两种方法在刷新页面后无法返回上一级页面, 重定向是让当前页面出栈,新页面入栈。

JavaScript将数字转换为字符串

1.方法String()
String(123)
2.Number方法toString()
x.toString()

HBuilder

页面

pages.json中有各个页面的具体介绍。

样式

可在static/scss文件下引用colorui.cssicon.css并且形成一个index.scss引入样式。

再在App.vue文件中引用index.scss

打包
  • 首先在manifest.json中配置应用名称、应用版本、图标、权限等信息。
  • 然后点击发行,选择原生App-云打包。
  • 一般自己调试点击使用公共测试证书,其它信息默认,点击打包。
  • 打包后的apk一般在项目的unpackage/release/apk目录下。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值