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

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.

主站蜘蛛池模板: 城口县| 若羌县| 贡嘎县| 福清市| 汪清县| 漳浦县| 司法| 怀化市| 祥云县| 涪陵区| 濉溪县| 澎湖县| 阿荣旗| 陕西省| 河南省| 鄂伦春自治旗| 高淳县| 金华市| 平乡县| 贵定县| 汝阳县| 崇仁县| 靖州| 姜堰市| 府谷县| 图们市| 富顺县| 曲沃县| 泰安市| 昌宁县| 兰州市| 酉阳| 宜丰县| 兰考县| 云梦县| 江山市| 新密市| 营口市| 桦甸市| 四平市| 称多县|