官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 乌兰浩特市| 青田县| 青河县| 全州县| 洪江市| 宁德市| 三江| 潢川县| 九龙城区| 孝感市| 任丘市| 台州市| 增城市| 都匀市| 竹北市| 武陟县| 合水县| 陈巴尔虎旗| 微山县| 壤塘县| 青海省| 多伦县| 曲阜市| 湖口县| 儋州市| 丰顺县| 沈阳市| 济南市| 汝城县| 华容县| 汤阴县| 依兰县| 临沂市| 鄢陵县| 顺义区| 灵宝市| 景谷| 贵港市| 阳城县| 乃东县| 石首市|