Vuejs2 如何使用<;插槽>;,谁能给我一个样品演示?
我正在学习Vue框架,不懂如何使用,谁能给我看一个示例演示?Vuejs2 如何使用<;插槽>;,谁能给我一个样品演示?,vuejs2,Vuejs2,我正在学习Vue框架,不懂如何使用,谁能给我看一个示例演示? 非常感谢。作为来自 假设您希望呈现名为“基本布局”的给定模板 <div class="container"> <header> <!-- We want header content here --> </header> <main> <!-- We want main content here --> </main>
非常感谢。作为来自 假设您希望呈现名为“基本布局”的给定模板
<div class="container">
<header>
<!-- We want header content here -->
</header>
<main>
<!-- We want main content here -->
</main>
<footer>
<!-- We want footer content here -->
</footer>
</div>
所以插槽基本上就像占位符一样,可以命名,您可以在确切的位置发送信息。@Doc谢谢您的回答和提示。我制作了一个演示:
<!DOCTYPE html>
<html>
<head>
<title>39、slot !</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<alert-box>
Something bad happened.
</alert-box>
</div>
<script>
Vue.component('alert-box', {
template: `
<div class="demo-alert-box">
<strong>Error!</strong>
<slot></slot>
</div>
`
})
var app = new Vue({
el:'#app'
})
</script>
</body>
</html>
39、吃角子老虎!
坏事情发生了。
Vue.组件(“警报框”{
模板:`
错误!
`
})
var app=新的Vue({
el:“#应用程序”
})
插槽只是父子之间提供的数据的占位符。它们告诉我们在哪里放置任何给定的数据。参考更多信息我已经看到了这个链接,你能给我一个像这样的示例演示看看我的答案吗。问问你是否还有任何疑问。
<div class="container">
<!-- this is where the 'header' slot was -->
<h1>Here might be a page title</h1>
<!-- this is where the main slot was -->
<p>A paragraph for the main content.</p>
<p>And another one.</p>
<!-- this is where the footer slot was -->
<p>Here's some contact info</p>
<!DOCTYPE html>
<html>
<head>
<title>39、slot !</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<alert-box>
Something bad happened.
</alert-box>
</div>
<script>
Vue.component('alert-box', {
template: `
<div class="demo-alert-box">
<strong>Error!</strong>
<slot></slot>
</div>
`
})
var app = new Vue({
el:'#app'
})
</script>
</body>
</html>