作者是在添加显示轮播图面板指示点时,出现报错信息:
报错原代码(任一页面的.vue文件)
<template><swiper indicator-dots><swiper-item v-for = "item in picture" : key = "item.id"><view><image :src = "item.img"></image></view></swiper-item></swiper>
</template><script>export default {data() {return {title: 'Hello uni',//轮播图数据picture : [{ id: '1', img: "/static/tabs/home_default.png"},{ id: '2', img: "/static/tabs/home_selected.png"}]}},onLoad() {},methods: {}}
</script><style>.content {display: flex;flex-direction: column;align-items: center;justify-content: center;}.text-area {display: flex;justify-content: center;}.title {font-size: 36rpx;color: #8f8f94;}
</style>
其中第三行代码:
<swiper-item v-for = "item in picture" : key = "item.id">
-
v-for
和:key
之间的 等号(=)前后有空格,且:key
的写法不规范。 -
正确的写法应该是
v-for="item in picture" :key="item.id"
(无空格,:
直接绑定)。
修改后:
<swiper-item v-for = "item in picture" :key="item.id">
控制台提示信息:
页面预览:
面板指示点成功显示