Skip to content

Instantly share code, notes, and snippets.

@zidom
Created January 26, 2018 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zidom/bfece2dcd865334bab9a3cde82b77477 to your computer and use it in GitHub Desktop.
Save zidom/bfece2dcd865334bab9a3cde82b77477 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/podicoz
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<h4>Demo 1</h4>
<div id="app">
<vlist>
<span slot="slot1-0" slot-scope="{index}" >Hi {{index}} !</span>
<span slot="slot2-2" slot-scope="{index}" >some body! {{index}} !</span>
</vlist>
</div>
<hr>
<h3>Demo 2</h3>
<h4>How can i do it like follow code?</h4>
<div id="app1">
<vlist>
<span :slot="`slot1-${index}`" slot-scope="{index}">Hi {{index}} ! </span>
<span :slot="`slot2-${index}`" slot-scope="{index}">嗯哼!{{index}} !</span>
</vlist>
</div>
<script type="text/x-template" id="mylist">
<ul>
<li v-for="(c, idx) in ['a','b','c','d']" :key='idx'>
{{c}}:
<slot :name="`slot1-${idx}`" :index="idx"><slot>
<slot :name="`slot2-${idx}`" :index="idx"><slot>
</li>
</ul>
</script>
<script>
Vue.component('vlist',{
template:'#mylist'
})
new Vue({
el:'#app'
})
new Vue({
el:'#app1'
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment