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

How to assign value to src attribute through Vue using v-for (detailed tutorial)

亚连
Release: 2018-06-01 15:26:48
Original
2561 people have browsed it

Below I will share with you an article on how Vue uses v-for to assign values ​​to the src attribute. It has a good reference value and I hope it will be helpful to everyone.

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 : &#39;img1&#39; },
        { img : &#39;img2&#39; },
        { img : &#39;img3&#39; },
        { img : &#39;img4&#39; }        
      ]
    }
  },
})
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

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

JS method of traversing irregular multi-dimensional arrays

Vue project closes eslint verification

Two methods to remove code specification detection in vue

The above is the detailed content of How to assign value to src attribute through Vue using v-for (detailed tutorial). 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!