关于name
来源:2-10 Vue项目首页 - 开发周末游组件
青旗
2020-11-19 20:47:36
# 具体遇到的问题
export default 里面的name 没改 看着也没有问题 这个name有什么用 一般什么情况下使用
# 报错信息的截图
# 相关课程内容截图
# 尝试过的解决思路和结果
# 粘贴全部相关代码,切记添加代码注释(请勿截图)
<template>
<div>
<div class="title">热销推荐</div>
<ul>
<li
class="item border-bottom"
v-for="item of recommendList"
:key="item.id"
>
<img class="item-img" :src="item.imgUrl" />
<div class="item-info">
<p class="item-title">{{ item.title }}</p>
<p class="item-desc">{{ item.desc }}</p>
<button class="item-button">查看详情</button>
</div>
</li>
</ul>
</div>
</template>
<script>
export default {
name: "HomeRecommend",
data() {
return {
recommendList: [
{
id: "0001",
imgUrl:
"https://imgs.qunarzz.com/sight/p0/1411/61/d92ba6a30aa12eb0a9a4a9c82214cb8e.water.jpg_200x200_eebad140.jpg",
title: "秦始皇帝陵博物院(兵马俑)",
desc:
"一场时空穿越的旅行,探寻历史悠久的文化古都!寻觅历史留下的点点足迹,细细品味古人的伟大",
},
{
id: "0002",
imgUrl:
"https://imgs.qunarzz.com/sight/p0/1411/61/d92ba6a30aa12eb0a9a4a9c82214cb8e.water.jpg_200x200_eebad140.jpg",
title: "秦始皇帝陵博物院(兵马俑)",
desc:
"一场时空穿越的旅行,探寻历史悠久的文化古都!寻觅历史留下的点点足迹,细细品味古人的伟大",
},
{
id: "0003",
imgUrl:
"https://imgs.qunarzz.com/sight/p0/1411/61/d92ba6a30aa12eb0a9a4a9c82214cb8e.water.jpg_200x200_eebad140.jpg",
title: "秦始皇帝陵博物院(兵马俑)",
desc:
"一场时空穿越的旅行,探寻历史悠久的文化古都!寻觅历史留下的点点足迹,细细品味古人的伟大",
},
],
};
},
};
</script>
<style scoped>
.title {
margin-top: 0.2rem;
line-height: 0.8rem;
background: #eee;
text-indent: 0.2rem;
}
.item {
overflow: hidden;
display: flex;
height: 1.9rem;
}
.item-img {
width: 1.7rem;
height: 1.7rem;
padding: 0.1rem;
}
.item-info {
flex: 1;
padding: 0.1rem;
min-width: 0;
}
.item-title {
line-height: 0.54rem;
font-size: 0.32rem;
}
.item-desc {
line-height: 0.4rem;
color: #ccc;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.item-button {
line-height: 0.44rem;
margin-top: 0.16rem;
background: #ff9300;
padding: 0 0.2rem;
border-radius: 0.06rem;
color: #fff;
}
</style>
1回答
同学你好,name用来给组件命名 ,它的主要作用是:
(1)递归组件(递归组件是指组件自身调用自身)时用
(2)取消缓存时用
以上关于name的介绍,老师在课程中都会讲解。祝学习愉快~
相似问题