Last active
October 10, 2019 15:37
-
-
Save CreatiCoding/3186c62f015c2c22cf7761647909487d to your computer and use it in GitHub Desktop.
vue slots scope custom component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <div> | |
| <List #List="list" :contents="[{name:1}, {name:2}]"> | |
| <div>{{list.content}}</div> | |
| </List> | |
| </div> | |
| </template> | |
| <script> | |
| import List from './List'; | |
| export default { | |
| name: 'app', | |
| components: { List }, | |
| }; | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <template> | |
| <div> | |
| <div v-for="(content, index) in contents" :key="`key_${identifier}_${index}`"> | |
| <slot name="List" :content="content"></slot> | |
| </div> | |
| </div> | |
| </template> | |
| <script> | |
| export default { | |
| name: 'List', | |
| computed: { | |
| identifier() { | |
| return ( | |
| Math.random() | |
| .toString(36) | |
| .substring(2, 15) + | |
| Math.random() | |
| .toString(36) | |
| .substring(2, 15) | |
| ); | |
| }, | |
| }, | |
| props: { | |
| contents: { | |
| type: Array, | |
| default: () => [], | |
| }, | |
| }, | |
| }; | |
| </script> | |
| <style scoped> | |
| </style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment