具名插槽的使用

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>
原文地址:https://www.cnblogs.com/ch2020/p/14846618.html