帖子
帖子
用户
博客
课程
显示全部楼层
288
帖子
4
勋章
5万+
Y币

[多端开发] 在V-for 中 使用 v-model 绑定循环的数据问题

[复制链接]
发表于 2021-4-16 16:28:35
具体报错为:
Cannot read property 'name' of undefined

直接上代码吧,不知道该咋描述了
  1. <template name='order_evaluation'>
  2.         <view class="page">
  3.                 <scroll-view scroll-y show-scrollbar="false" class="flex-1">
  4.                         <view class="goods-box">
  5.                                 <view v-for="(items,index) in list" class="">
  6.                                         <textarea name="" id="" cols="30" rows="10" v-model="items.name"></textarea>
  7.                                 </view>
  8.                         </view>
  9.                 </scroll-view>
  10.         </view>
  11. </template>
  12. <script>
  13. export default {
  14.         name: 'order_evaluation',
  15.         apiready() {//like created

  16.         },
  17.         data() {
  18.                 return {
  19.                         list: [{
  20.                                 name: ''
  21.                         }, {
  22.                                 name: 1
  23.                         }]
  24.                 }
  25.         },
  26.         methods: {
  27.                 back() {
  28.                         api.closeWin()
  29.                 }
  30.         }
  31. }
  32. </script>
  33. <style>
  34. .flex-1 {
  35.         flex: 1;
  36. }
  37. .disflex-v-center {
  38.         flex-flow: row;
  39.         align-items: center;
  40.         justify-content: flex-start;
  41. }
  42. .width-100p {
  43.         width: 100%;
  44. }
  45. .bg-f7 {
  46.         background: #f7f7f7;
  47. }
  48. .position {
  49.         position: absolute;
  50.         bottom: 14px;
  51.         right: 10px;
  52. }
  53. .text-box {
  54.         margin-top: 10px;
  55.         /* width: 100%; */
  56.         margin-left: 14px;
  57.         margin-right: 14px;
  58.         height: 86px;
  59.         background: #f7f7f7;
  60.         position: relative;
  61. }
  62. .c999 {
  63.         color: #999;
  64. }
  65. .img-style {
  66.         width: 61px;
  67.         height: 61px;
  68.         border-radius: 6px;
  69. }
  70. .padding-14 {
  71.         padding: 14px 14px 10px 14px;
  72. }
  73. .goods-box {
  74.         width: 100%;
  75.         height: 347px;
  76.         background: #ffffff;
  77.         border-radius: 10px;
  78. }
  79. .page {
  80.         height: 100%;
  81.         background: #f7f7f7;
  82. }
  83. </style>
复制代码
大佬你测试一下就知道了
10
帖子
1
勋章
5698
Y币
我来描述一下吧:

在 v-for 中使用 v-model 时使用 v-for中的数据作用域被关联到了组件this的data中了。

如图:
QQ图片20210416163300.png
76
帖子
0
勋章
2613
Y币
看下是否楼上说的问题
25
帖子
0
勋章
119
Y币
这个和VUE的语法还是有很大差异的
您需要登录后才可以回帖 登录

本版积分规则