<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
<title>作用域插槽</title>
</head>
<body>
<style>
#app{
border: 1px solid;
padding:10px;
text-align: center;
}
</style>
<div id="app">
<my-component><!--2、在template模板中定义slot-scope,等号接一个临时的变量名 prop-->
<template slot="abc" slot-scope="prop">
{{ prop.text}}<!--3、在template 模板中 以文本插值形式 获取子组件数据-->
</template>
<!--其中 2.5.0版本之前 只能在 template 标签上用 slot, slot-scope ,而且template标签永远不会渲染,渲染是它里面的内容!-->
<!--2.5.0版本后,可以在别的标答上用 slot,slot-scope ,而且在什么标签上用,什么标签及标签内容都会渲染出来-->
<p slot="abc" slot-scope="prop">
{{prop.text}}
</p>
</my-component>
</div>
<script>
var app = new Vue({
el: '#app',
components:{
'my-component':{
template:'<div>\
<slot text="我是来自子组件" name="abc">\
</slot>\
</div>'//1、在子组件定义一个slot,写上要传递的数据
}
}
})
</script>
</body>
</html>
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |