【20】vue.js — slot佔位符
預設情況下我們使用元件會將元件標籤內的內容給替換掉,不會顯示元件內的內容
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="js/vue.js"></script>
<style>
</style>
</head>
<body>
<div id="box">
<aaa>
<ul>
<li>1111</li>
<li>2222</li>
<li>3333</li>
</ul>
</aaa>
</div>
<script>
var vm=new Vue({
el:'#box',
data:{
a:'aaa'
},
components:{
'aaa':{
template:'<h1>xxxx</h1>'
}
}
});
</script>
</body>
</html>
使用slot來佔位
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/vue.js" ></script>
</head>
<body>
<div id="box">
<aaa>
<ul>
<li>111</li>
<li>222</li>
<li>333</li>
</ul>
</aaa>
<hr />
<aaa></aaa>
</div>
<template id="aaa">
<h1>我是模板一</h1>
<slot>這是預設的情況</slot>
<p>welcome vue</p>
</template>
</body>
<script>
var vm = new Vue({
el: '#box',
components: {
'aaa': {
template: '#aaa'
}
}
});
</script>
</html>
有區分的替換佔位
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/vue.js" ></script>
</head>
<body>
<div id="box">
<aaa>
<ul slot="ul-slot">
<li>111</li>
<li>222</li>
<li>333</li>
</ul>
<ol slot="ol-slot">
<li>aaa</li>
<li>bbb</li>
<li>ccc</li>
</ol>
</aaa>
<hr />
<aaa></aaa>
</div>
<template id="aaa">
<h1>我是模板一</h1>
<slot name="ul-slot">ul替換佔位符</slot>
<slot name="ol-slot">ol替換佔位符</slot>
<p>welcome vue</p>
</template>
</body>
<script>
var vm = new Vue({
el: '#box',
components: {
'aaa': {
template: '#aaa'
}
}
});
</script>
</html>
相關文章
- SCSS % 佔位符CSS
- golang fmt 格式 “佔位符”Golang
- 詳解 Go 語言中 20 個佔位符!Go
- html 空白漢字佔位符HTML
- golang 佔位符還傻傻分不清?Golang
- 使用PreparedStatement為佔位符?賦值賦值
- SpringBoot配置檔案佔位符Spring Boot
- 問題:mybatis like 佔位符處理MyBatis
- wpf兩種佔位符實現方式
- Vue.js——slot-插槽的基本使用——2020.12.7Vue.js
- 字元編碼及空白漢字佔位符字元
- python切片如何作為佔位符使用Python
- C++ 預設引數和佔位符C++
- Python 佔位符格式化詳解Python
- 認真一點學 Go:17. 詳解 20 個佔位符Go
- SpringBoot專案配置檔案佔位符Spring Boot
- html 空白漢字佔位符 HTML
- 適當的方式模仿UITextField佔位符的顏色UI
- 聊聊 SpringBoot 中的兩種佔位符:@*@ 和 ${*}Spring Boot
- dubbo註冊中心佔位符無法解析問題
- Vue.js 你需要知道的 v-slot (譯)Vue.js
- dubbo註冊中心佔位符無法解析問題(二)
- 關於python中format佔位符中的 {!} 引數PythonORM
- 配置檔案或者模板中的佔位符替換工具類
- [Vue] slot詳解,slot、slot-scope和v-slotVue
- TensorFlow常量、變數和佔位符詳解(學習筆記)變數筆記
- 2.9Python基礎語法(7):轉義字元&佔位符Python字元
- 05.Beetl標籤函式以及定界符、佔位符介紹—《Beetl視訊課程》函式
- Godot 4.0 載入為佔位符(InstancePlaceholder)的用法和特點Go
- Swift3.0語言教程使用佔位符格式建立和初始化字串Swift字串
- 【Java】位操作符Java
- 聊聊如何修復springboot使maven-resources-plugin佔位符失效問題Spring BootMavenPlugin
- 【Spring原始碼分析】.properties檔案讀取及佔位符${...}替換原始碼解析Spring原始碼
- iframe 高度設定為0時還有佔位_iframe佔位
- 在scanf函式中佔位符使用錯誤而產生的一些錯誤函式
- 【譯】Vue 的小奇技(第四篇):Vue.js 2.6.0 中的新指令 v-slotVue.js
- vue插槽slotVue
- vue slot 用法Vue