- Vue.js Quick Start Guide
- Ajdin Imsirovic
- 239字
- 2021-06-24 18:23:57
Understanding components, templates, and props
To begin, let's look at how to make a component in Vue. First, we specify the component, like this:
Vue.component('custom-article', {
template: `
<article>
Our own custom article component!<span></span>
</article>`
})
new Vue({
el: '#app'
})
A component is a block of code that we give a custom name. This custom name can be anything we come up with, and it's a single label for that entire block of code in the form of a custom HTML tag. In the previous example, we grouped the article and span tags and gave that custom tag the name of custom-article.
The code for this component is available as a Codepen at https://codepen.io/AjdinImsirovic/pen/xzpOaJ.
Now, to create an instance of our component, we simply use our <custom-article> opening and closing tags in our HTML, like this:
<main id="app">
<custom-article></custom-article>
</main>
The parent is the actual Vue instance.
Note that you can use string templates even without a component. You simply add the template option to your Vue instance, like this:
//HTML
<main id="app"></main>
//JS
new Vue({
el: '#app',
template: '<article>A string template without a component!<span></span></article>'
})
The example code for the previous example is available here: https://codepen.io/AjdinImsirovic/pen/RJxMae.
Next, we'll see how we can improve our component with the help of the props and data options.
- 智慧城市:大數據、互聯網時代的城市治理(第4版)
- 數字通信同步技術的MATLAB與FPGA實現:Altera/Verilog版(第2版)
- 電力物聯網工程技術原理與應用
- Spring 5.0 Projects
- 智慧光網絡:關鍵技術、應用實踐和未來演進
- Master Apache JMeter:From Load Testing to DevOps
- 通信十年:擁抱互聯網
- 網絡AI+:2030后的未來網絡
- 移動物聯網:商業模式+案例分析+應用實戰
- 中國互聯網發展報告2021
- 計算機通信網絡安全
- 新IP:面向泛在全場景的未來數據網絡
- Building Microservices with Spring
- 互聯網心理學:新心理與行為研究的興起
- 賽博空間簡史