slot插槽:调取组件时候,把写在组件的中间部分的内容获取到,放置到组件的某个位置(具体位置根据需求),借助这个方法,可以让当前组件按具备更强的扩展性
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>珠峰培训</title></head><body><!--父调用子组件的方法--><div id="app"><!--这里放的内容均属于父级当前模板的 只有属性名是属于组件的--><modal m="1"><a href="http://www.zhufengpeixun.cn">去珠峰</a><p slot="content" @click="fn">亲确认删除吗</p><h1 slot="title">是否删除?</h1><a href="http://www.zhufengpeixun.cn">去珠峰</a></modal></div><!--slot作用 定制模板--><!--模板中只能有一个根元素,可以通过元素属性定制模板--><!--slot中可以放置一些默认的内容,如果传递了内容则替换掉--><!--如果没有名字的标签默认会放置到default中--><template id="modal"><div><slot name="title">默认标题</slot><slot name="content">默认内容</slot><slot name="default">这是一个默认标题</slot></div></template><script src="node_modules/vue/dist/vue.js"></script><script>let modal = {template:'#modal',};let vm = new Vue({el:'#app',components:{modal},methods:{fn(){alert(1)}},data:{}})</script></body></html>
