- Vue.js 2.x by Example
- Mike Street
- 151字
- 2021-07-02 20:00:26
Declarative rendering
Regular HTML attributes, such as the src of the <img> tag, can be dynamically populated with Vue using the v-bind: attribute. This allows you to populate any existing attribute with data from your Vue application. This might be an image source or element ID.
The bind option gets used by prepending the attribute you wish to populate. For example, if you wished to populate an image source with the value of a data key called imageSource, you would do the following:
View:
Create an img tag in your view app space, with a dynamic src attribute, using v-bind and a variable called imageSource.
<p id="app">
<img v-bind:src="imageSource">
</p>
JavaScript:
Create a variable in your Vue JavaScript code called imageSource. Add the URL to the desired image:
const app = new Vue({
el: '#app',
data: {
imageSource: 'http://via.placeholder.com/350x150'
}
});
The v-bind: attribute can be shortened to just :, so, for example, v-bind:src would become :src.
- DevOps:軟件架構(gòu)師行動指南
- Java語言程序設(shè)計
- Bootstrap Site Blueprints Volume II
- Mastering ServiceStack
- Java完全自學(xué)教程
- PHP程序設(shè)計(慕課版)
- 深入淺出RxJS
- Linux命令行與shell腳本編程大全(第4版)
- 程序設(shè)計基礎(chǔ)教程:C語言
- RealSenseTM互動開發(fā)實戰(zhàn)
- Visual Basic程序設(shè)計習(xí)題與上機實踐
- QGIS 2 Cookbook
- Python Machine Learning Blueprints:Intuitive data projects you can relate to
- HTML5移動Web開發(fā)
- Python預(yù)測分析實戰(zhàn)