本文主要是介绍07|Vue组件的核心概念:插槽,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
文章目录
实例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id='app'>
{{message}} {{message + message}}
<div :id="message"></div>
<todo-list>
<template v-slot>
<todo-item @delete="handlerDelete" v-for="item in list" data-test="dd" :title="item.title" :del="item.del">
<template v-slot:pre-icon1="{value}">
<span>前置图标1 {{value}} </span>
</template>
<template v-slot:suf-icon1>
<span>后置图标1 </span>
</template>
<span slot="pre-icon2">前置图标2 </span>
</todo-item>
</template>
</todo-list>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script>
Vue.component('todo-item', {
props: {
title: String,
del: {
type: Boolean,
default: false
}
},
template: '' +
'<li>\n' +
'<slot name="pre-icon1" :value="value"></slot>' +
'<slot name="pre-icon2"></slot>' +
'<span v-if="del"> {{title}} </span>\n' +
'<span v-else style="text-decoration: line-through"> {{title}} </span>\n' +
'<slot name="suf-icon1"></slot>' +
'<slot name="suf-icon2">
这篇关于07|Vue组件的核心概念:插槽的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!