当前位置:网站首页>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>
边栏推荐
猜你喜欢
22.支持向量机—高斯核函数
Artifact XXXwar exploded Artifact is being deployed, please wait...(已解决)
中缀转后缀、前缀表达式快速解决办法
How to solve the error when mysql8 installs make
Interview high-frequency test questions solution - stack push and pop sequence, effective parentheses, reverse Polish expression evaluation
Short video seo search optimization main content
面试高频考题解法——栈的压入弹出序列、有效的括号、逆波兰表达式求值
很多人喜欢用多御安全浏览器,竟是因为这些原因
一文概览最实用的 DeFi 工具
PHP从txt文件中读取数据的方法
随机推荐
security 会话并发管理
TCP 可靠吗?为什么?
如何重装Win11?一键重装Win11方法
Cash Ⅱ LeetCode_518_ change
Async/await principle and execution sequence analysis
TCL: Pin Constraints Using the tcl Scripting Language in Quartus
Detailed explanation of Zadig's self-testing and tuning environment technical solution for developers
Keepalived 高可用的三种路由方案
零基础如何学习单片机,一位入门者的进阶路径,可参考
JSP 如何获取request对象中的路径信息呢?
如何设计循环队列?快进来学习~
电机原理动图合集
08-SDRAM: Summary
QML包管理
[Headline] Written test questions - minimum stack
微软电脑管家V2.1公测版正式发布
扑克牌问题
asyncawait和promise的区别
els block deformation judgment.
JSP out.println()方法具有什么功能呢?