{"action":"created","issue":{"url":"https://api.github.com/repos/Tencent/wepy/issues/280","repository_url":"https://api.github.com/repos/Tencent/wepy","labels_url":"https://api.github.com/repos/Tencent/wepy/issues/280/labels{/name}","comments_url":"https://api.github.com/repos/Tencent/wepy/issues/280/comments","events_url":"https://api.github.com/repos/Tencent/wepy/issues/280/events","html_url":"https://github.com/Tencent/wepy/issues/280","id":245434779,"node_id":"MDU6SXNzdWUyNDU0MzQ3Nzk=","number":280,"title":"repeat中使用组件，组件中无法取到props传入的值","user":{"login":"Aron-YCS","id":16283697,"node_id":"MDQ6VXNlcjE2MjgzNjk3","avatar_url":"https://avatars0.githubusercontent.com/u/16283697?v=4","gravatar_id":"","url":"https://api.github.com/users/Aron-YCS","html_url":"https://github.com/Aron-YCS","followers_url":"https://api.github.com/users/Aron-YCS/followers","following_url":"https://api.github.com/users/Aron-YCS/following{/other_user}","gists_url":"https://api.github.com/users/Aron-YCS/gists{/gist_id}","starred_url":"https://api.github.com/users/Aron-YCS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aron-YCS/subscriptions","organizations_url":"https://api.github.com/users/Aron-YCS/orgs","repos_url":"https://api.github.com/users/Aron-YCS/repos","events_url":"https://api.github.com/users/Aron-YCS/events{/privacy}","received_events_url":"https://api.github.com/users/Aron-YCS/received_events","type":"User","site_admin":false},"labels":[{"id":481100581,"node_id":"MDU6TGFiZWw0ODExMDA1ODE=","url":"https://api.github.com/repos/Tencent/wepy/labels/Inactive","name":"Inactive","color":"eeeeee","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2017-07-25T15:10:47Z","updated_at":"2019-01-03T12:30:46Z","closed_at":"2018-06-20T02:34:58Z","author_association":"NONE","body":"代码如下：\r\n组件：com1\r\n```\r\n<template>\r\n  <view class=\"com1\">\r\n    <text>{{ value }}</text>\r\n  </view>\r\n</template>\r\n...\r\n  props = {\r\n    value: String\r\n  }\r\n  onLoad () {\r\n    setInterval(() => {\r\n      console.log('com1: ', this.value)\r\n    }, 1000)\r\n  }\r\n...\r\n```\r\n\r\n```\r\n<repeat for=\"{{testArray}}\" key=\"index\" index=\"index\" item=\"item\">\r\n  <com1 :value.sync=\"item.text\"></com1>\r\n</repeat>\r\n```\r\n\r\ncom1中的onLoad里，拿不到props传入的数据，用interval输出，一直是undefined"},"comment":{"url":"https://api.github.com/repos/Tencent/wepy/issues/comments/451130230","html_url":"https://github.com/Tencent/wepy/issues/280#issuecomment-451130230","issue_url":"https://api.github.com/repos/Tencent/wepy/issues/280","id":451130230,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MTEzMDIzMA==","user":{"login":"BranceLee","id":37168881,"node_id":"MDQ6VXNlcjM3MTY4ODgx","avatar_url":"https://avatars0.githubusercontent.com/u/37168881?v=4","gravatar_id":"","url":"https://api.github.com/users/BranceLee","html_url":"https://github.com/BranceLee","followers_url":"https://api.github.com/users/BranceLee/followers","following_url":"https://api.github.com/users/BranceLee/following{/other_user}","gists_url":"https://api.github.com/users/BranceLee/gists{/gist_id}","starred_url":"https://api.github.com/users/BranceLee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BranceLee/subscriptions","organizations_url":"https://api.github.com/users/BranceLee/orgs","repos_url":"https://api.github.com/users/BranceLee/repos","events_url":"https://api.github.com/users/BranceLee/events{/privacy}","received_events_url":"https://api.github.com/users/BranceLee/received_events","type":"User","site_admin":false},"created_at":"2019-01-03T12:30:46Z","updated_at":"2019-01-03T12:30:46Z","author_association":"NONE","body":"###  和你分享一波，\r\n父组件data 里 list：[1,2,3]，\r\n通过list.sync给子组件传值，\r\n确实子组件在onLoad 或者整个过程都无法拿到list 的值，回报undefined:\r\n### 解决方案：\r\n在父组件的onLoad 生命周期里，对data里的list 进行赋值（覆盖不一样的值），就能解决子组件无法拿到值的问题，个人感觉他的运行原理是通过新旧数据不一致的时候取第二次不一值的数据来改变，\r\n#### 测试案例\r\n```js\r\n  data = {\r\n    brandCode: '021',\r\n    list: [1, 2, 3, 4, 5, 6, 7, 8],\r\n    skuval: '',\r\n    category: {},\r\n    sortCode: 1\r\n  };\r\n  buttonPress() {\r\n    this.list = [1, 2, 3, 4, 5, 6, 7];\r\n  }\r\n```\r\n// 初始不会显示1-8，当点击button时出现数字\r\n### 最终解决个人方案\r\n```js\r\n data = {\r\n    list: [],\r\n  };\r\n\r\n  onLoad(option) {\r\n    //初始赋值data\r\n    this.list = [1, 2, 3, 4, 5, 6, 7, 8];\r\n  }\r\n```\r\n如果对你有帮助记得点赞哦😀🍾😀🍾😀"}}
{"actor":{"display_login":"BranceLee"}}