Skip to content

Instantly share code, notes, and snippets.

@CreatiCoding
Last active October 10, 2019 15:37
Show Gist options
  • Select an option

  • Save CreatiCoding/3186c62f015c2c22cf7761647909487d to your computer and use it in GitHub Desktop.

Select an option

Save CreatiCoding/3186c62f015c2c22cf7761647909487d to your computer and use it in GitHub Desktop.
vue slots scope custom component
<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>
<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