具名插槽的使用

slot 具名插槽的使用

给slot取上别名

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div id="app">
    {{message}}
  <cpn>
    <span slot="center">搜索信息</span>
  </cpn>
</div>
<script src="../vue.js"></script>
<template id="cpn">
  <div>
    <slot name="left"><span>左边</span></slot>
    <slot name="center"><span>中间</span></slot>
    <slot name="right"><span>右边</span></slot>
  </div>
</template>
<script>
  const app = new Vue({
    el: '#app',
    data: {
      message: 'hello'
    },
    components: {
      cpn: {
        template: '#cpn'
      }
    }
  })
</script>
</body>
</html>
posted @ 2021-06-03 19:54  竹石2020  阅读(50)  评论(0编辑  收藏  举报