- 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.
- Android Jetpack開發(fā):原理解析與應用實戰(zhàn)
- R語言數(shù)據(jù)可視化實戰(zhàn)
- Spring Cloud、Nginx高并發(fā)核心編程
- Hands-On RESTful Web Services with Go
- Spring Boot企業(yè)級項目開發(fā)實戰(zhàn)
- Webpack實戰(zhàn):入門、進階與調優(yōu)
- C++編程兵書
- Python數(shù)據(jù)可視化之美:專業(yè)圖表繪制指南(全彩)
- Instant Zurb Foundation 4
- Python大規(guī)模機器學習
- Learning Jakarta Struts 1.2: a concise and practical tutorial
- 計算語言學導論
- MATLAB 2020 GUI程序設計從入門到精通
- Java從入門到精通(視頻實戰(zhàn)版)
- 透視C#核心技術:系統(tǒng)架構及移動端開發(fā)