当前位置:网站首页>Problem: when the attribute in the data object (defined data) in the access component is also the attribute in the object object, an error is reported
Problem: when the attribute in the data object (defined data) in the access component is also the attribute in the object object, an error is reported
2022-06-23 06:44:00 【Xiaoxia】
Parent component :
export default {
setup(){
const route=useRoute()
let state=reactive({
list:[],
playList:{
}
})
provide("playList",computed(()=>state.playList))
onMounted(async ()=>{
console.log(route,'route')
let id=route.query.id
let res=await getPlayListDetail(id)
console.log(res,' Details of the song list ')
state.playList=res.data.playlist
})
return{
state
}
},
components:{
ListViewTop
}
}
Child components :
Interface
<div class="contentRight">
<h3>{
{playList.name}}</h3>
<div class="author">
<img :src="playList.creator.avatarUrl" class="header">
<span>{
{playList.creator.nickname}}</span>
</div>
<div class="description">
{
{playList.description}}
</div>
</div>
</div>
js Code
setup(){
// Omit
let playList=inject('playList')
}
explain :
Use... In subcomponents playList.creator.avatarUrl Will report a mistake , The hint doesn't exist , Because the initial playList It's empty , Directly access the attributes of the array or object inside , Such as creator The property of will report an error
Correct the post parent component :
export default {
setup(){
const route=useRoute()
let state=reactive({
list:[],
playList:{
// Because initially playList It's empty , Directly access the attributes of the array or object inside , Such as creator The property of will report an error
// You can test it manually
// let person={
// age;12
// }
// console.log(person.age)//undefined
// console.log(person.friend.name)// Report errors
creator:{
},// initialization
tracks:[]
}
})
provide("playList",computed(()=>state.playList))
onMounted(async ()=>{
console.log(route,'route')
let id=route.query.id
let res=await getPlayListDetail(id)
console.log(res,' Details of the song list ')
state.playList=res.data.playlist
})
return{
state
}
},
components:{
ListViewTop
}
}
边栏推荐
- js中if逻辑过多,常见优化
- 云盒子联合深信服,为南京一中打造智慧双模教学资源分享平台
- 华为软件测试笔试真题之变态逻辑推理题
- 记一次GLIB2.14升级GLIB2.18的记录以及其中的步骤原理
- C# 获取DPI和真实分辨率的方式(可以解决一直是96的问题)
- 解析创客教育中的造物原理
- haas506 2.0开发教程-高级组件库-modem.sim(仅支持2.2以上版本)
- 索引——MySQL
- Laravel log channel 分组配置
- How to realize video call and live interaction in a small program when live broadcasting is so popular?
猜你喜欢

从 WAN 到 SD-WAN 边缘设备的网络架构

解析创客教育中的个性化学习进度

bootstrap如何清除浮动的样式

C # database reports errors. Let's have a look
Link of Baidu URL Parameters? Recherche sur le chiffrement et le décryptage des paramètres d'URL (exemple de Code)

How to realize video call and live interaction in a small program when live broadcasting is so popular?

haas506 2.0開發教程-高級組件庫-modem.sms(僅支持2.2以上版本)

Steam教育对国内大学生的影响力

Index - MySQL

华为软件测试笔试真题之变态逻辑推理题
随机推荐
C# DPI适配问题
中台库存中的实仓与虚仓的业务逻辑设计
phpStudy设置301重定向
How to build a data application system based on overall value for energy enterprises
关于职业态度
idea的去除转义的复制粘贴
2020 smart power plant industry insight white paper
了解学习 JSX 的工作方式
20220621 Three Conjugates of Dual Quaternions
For non dpdk kvm1.0 machines, set init Maxrxbuffers changed from 256 to 1024 to improve packet receiving capacity
c#数据库报错问题大家帮我看看吧
Coordinate transformation
Sklearn classification in sklearn_ Report & accuracy / recall /f1 value
JS to create an array (all elements are objects)
Get to know webassembly quickly
Qt 中 QVariant 使用总结
SAP execution transaction code mrrl error -no message was found for partner 100065-
QT creator builds osgearth environment (osgqt msvc2017)
MySQL5.6 (5.7-8) 基于shardingsphere5.1.1 Sharding-Proxy模式读写分离
Media industry under the epidemic situation, small program ecology driven digital transformation exploration