https://uniapp.dcloud.net.cn/
data(){
return {q:123}
}
this.q = 456
{{name}}
{{item.name}}
123
传:
收:
{
{this.abc}
……
props:[abc]
}
v-on:click="fn1"
传
uni.$emit('sendData',this.msg)
收
uni.$on('sendData',(e)=>{
})
pages.json
//第一页为首页
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "uni-app"
}
}
,{
"path" : "pages/cloud_page/cloud_page",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}
],
"tabBar": {
"list": [{
"pagePath": "pages/index/index",
"text": "首页"
}, {
"pagePath": "pages/cloud_page/cloud_page",
"text": "云服务"
}]
}
跳转方:
//在起始页面跳转到test.vue页面并传递参数
uni.navigateTo({
url: 'test?id=1&name=uniapp'
});
被跳转放:
// 在test.vue页面接受参数
export default {
onLoad: function (option) { //option为object类型,会序列化上个页面传递的参数
console.log(option.id); //打印出上个页面传递的参数。
console.log(option.name); //打印出上个页面传递的参数。
}
}
创建开发环境文件—在项目根文件夹下点击右键—创建uniCloud云开发环境—阿里云
关联开发环境—在uniCloud关联
初始化数据库 — 在uniCloud文件夹—database—右键—创建db_init.json
db_init.json代码格式
{
"bendibao": {
"data": [{
"id": 1,
"name": "美食",
"icon": "http://ww1.sinaimg.cn/large/006ThXL5ly1fj8w5i2onyj302u02umwz.jpg"
}, {
"id": 2,
"name": "洗浴足疗",
"icon": "http://ww1.sinaimg.cn/large/006ThXL5ly1fj8w5i2j4dj302u02umwy.jpg"
}, {
"id": 3,
"name": "结婚啦",
"icon": "http://ww1.sinaimg.cn/large/006ThXL5ly1fj8w5i56i0j302u02u744.jpg"
}, {
"id": 4,
"name": "卡拉OK",
"icon": "http://ww1.sinaimg.cn/large/006ThXL5ly1fj8w5i2uzvj302u02udfo.jpg"
}, {
"id": 5,
"name": "找工作",
"icon": "http://ww1.sinaimg.cn/large/006ThXL5ly1fj8w5i2rnlj302u02umwz.jpg"
}, {
"id": 6,
"name": "辅导班",
"icon": "http://ww1.sinaimg.cn/large/006ThXL5ly1fj8w5i2zloj302u02udfn.jpg"
}, {
"id": 7,
"name": "汽车保养",
"icon": "http://ww1.sinaimg.cn/large/006ThXL5ly1fj8w5i69eij302u02ua9w.jpg"
}, {
"id": 8,
"name": "租房",
"icon": "http://ww1.sinaimg.cn/large/006ThXL5ly1fj8w5i6j2lj302u02u0sj.jpg"
}, {
"id": 9,
"name": "装修",
"icon": "http://ww1.sinaimg.cn/large/006ThXL5ly1fj8w5i6z1pj302u02ua9u.jpg"
}]
}
}
// 获取数据库
const db=uniCloud.database()
// 获取集合表
const list=db.collection('bendibao')
exports.main = async () => {
// 获取表里面的数据 get()
const res= await list.get()
return res
};
在**.vue**中调用
data() {
return {
list: []
}
},
onLoad() {
this.getData()
},
methods: {
getData() {
// 调用云函数 uniCloud.callFunction()
uniCloud.callFunction({
// 云函数的名称(调用哪一个云函数)
name: 'getList',
success: (res) => {
console.log(res);
this.list = res.result.data
}
})
}
}