当前位置:网站首页>uni-app项目总结
uni-app项目总结
2022-08-02 00:03:00 【一指流沙q】
一、数组中出现__ob__: Observer无法取值
问题:
原因:
只是因为你太着急了!!!!
vue取值的方式是Ajax异步的,换句人话就是说,你还没有从数据库中取到值放到对应的数组中去你那边就开始取值,那肯定是取不到的,所以设一个延迟等去取完之后呢你在进行赋值即可!那么你就可以看到这个值了。
注意:若使用JSON.parse(JSON.stringify(数组)),得到依然是空数组。原因如上。
解决办法:设置延迟
setTimeout(()=>{
//这里就写你要执行的语句即可,先让数据库的数据加载进去数组中你在从数组中取值就好了
this.city=this.cityList[0].name
},800)
二、页面传参和接受参数
1.字符串
传递参数:
//在起始页面跳转到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); //打印出上个页面传递的参数。
}
}
2.对象或数组
传递参数:
//通过提供的JSON.stingify方法,将对象转换成字符串后传递
click:function(e){
var model = JSON.stringify(e.currentTarget.dataset.model);
wx.navigateTo({
url: '../detail/detail?model=' + model,
})
}
接收参数:
//接收
onLoad: function (options) {
//将字符串转换成对象
var bean = JSON.parse(options.model);
},
三、绑定样式:动态style / :style=“{css属性: 值}“
语法 :style="{css属性: 值}"
文章推荐:
<template>
<div>
<!-- :style="css属性:值" -->
<button @click="one">点击变色01</button>
<button @click="two">点击变色02</button>
<button @click="three">点击变色03</button>
<div :style="{backgroundColor : bl}">盒子</div>
</div>
</template>
<script>
export default {
data () {
return {
bl:'red'
}
},
methods: {
one(){
this.bl = 'blue'
},
two(){
this.bl = 'gold'
},
three(){
this.bl = 'orange'
}
}
}
</script>
<style>
</style>
边栏推荐
- 一文概览最实用的 DeFi 工具
- TCL: Pin Constraints Using the tcl Scripting Language in Quartus
- Collection of NFT tools
- 尚硅谷MySQL学习笔记
- TCP 可靠吗?为什么?
- Excel表格数据导入MySQL数据库
- Using the "stack" fast computing -- reverse polish expression
- 不了解SynchronousQueue?那ArrayBlockingQueue和LinkedBlockingQueue不会也不知道吧?
- Unity—四元数、欧拉角API+坐标系统
- 玩转NFT夏季:这份工具宝典值得收藏
猜你喜欢
带你搞懂MySQL隔离级别,两个事务同时操作同一行数据会怎样?
面试必问的HashCode技术内幕
GetHashCode方法与=
Detailed explanation of Zadig's self-testing and tuning environment technical solution for developers
Study Notes: The Return of Machine Learning
Zadig 面向开发者的自测联调子环境技术方案详解
08-SDRAM: Summary
【加密周报】经济衰退在加息气氛中蔓延 美联储“放手一搏”?盘点上周加密市场发生的重大事件
玩转NFT夏季:这份工具宝典值得收藏
双队列实现栈?双栈实现队列?
随机推荐
Excel导入和导出
JSP page指令errorPage属性起什么作用呢?
What is it like to trade for a living?
协作乐高 All In One:DAO工具大全
已知中序遍历数组和先序遍历数组,返回后序遗历数组
图解LeetCode——1161. 最大层内元素和(难度:中等)
Win11如何获得最佳电源效率?
async和await用法介绍
windows sql server 如何卸载干净?
GetHashCode与Equals
GIF making - very simple one-click animation tool
Double queue implementation stack?Dual stack implementation queue?
asyncawait和promise的区别
利用“栈”快速计算——逆波兰表达式
IP Core: FIFO
06-SDRAM :SDRAM控制模块
els block deformation
【Leetcode】1206. Design Skiplist
Ansible中的任务执行控制
Collection of NFT tools