Home > Web Front-end > H5 Tutorial > body text

How to assign value to src attribute using v-for

php中世界最好的语言
Release: 2018-03-27 15:58:19
Original
2259 people have browsed it

This time I will show you how to use v-for to assign a value to the src attribute, and what are the precautions for using v-for to assign a value to the src attribute. The following is a practical case. Let’s take a look.

My code structure is as shown in the code below, which cannot be executed. The mustache notation cannot be used in the src attribute in img

<p id="test">
  <p v-for="item in lists">
    <img src="{{item.img}}">
  </p>
</p>
Copy after login
new Vue({
  el: "#test",
  data: function () {
    return {
      lists: [
        { img : 'img1' },
        { img : 'img2' },
        { img : 'img3' },
        { img : 'img4' }        
      ]
    }
  },
})
Copy after login

Later I changed the code in the html to the following

<p id="test">
  <p v-for="item in lists">
    <img v-bind:src="item.img">
  </p>
</p>
Copy after login

After using the v-bind tag, you can use it normally

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Detailed graphic explanation of Vue.directive()

The order of operating Vue rendering and plug-in loading

The above is the detailed content of How to assign value to src attribute using v-for. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template