slot插槽的基本使用

slot插槽的基本使用。

  • 插槽的默认值
  • 如果有多个值,同时放入到组件进行替换时,一起作为替换元素
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div id="app">
  {{message}}
  <cpn></cpn>
  <cpn><button>按钮</button></cpn>
</div>
<script src="../vue.js"></script>
<template id="cpn">
  <div>
    <h1>我是组件下面是插槽</h1>
    <slot><h2>haha </h2></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/14846573.html