Solve the problem of error when initializing the src attribute value of dynamically bound images in vue2.0

亚连
Release: 2018-05-30 14:10:05
Original
1694 people have browsed it

Below I will share with you an article that solves the problem of error when initializing the src attribute value of vue2.0 dynamic binding image. It has a good reference value and I hope it will be helpful to everyone.

In vue2.0, syntax similar to v-bind:src = " imgUrl " (abbreviation: src = " imgUrl ") is often used. Let's look at a case.

  
Copy after login

In the above case, since the data field captcha_id needs to be obtained through a network request, and the page has probably been rendered, a 404 error will occur every time it is loaded.

The picture The src attribute value is parsed as 'http://www.demo.com/static/.png' when initialized.

The solution is as follows:

computed: { imgUrl(){ if(this.captcha_id){ return this.$store.state.cmnUrl +'/v1/cmn/captcha/new/' + this.captcha_id + '.png' }else{ return null; } }, },
Copy after login

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

Related articles:

Vue’s browser storage method encapsulation example

Vue implements the method of exiting after prompting to save

Usage example of bootstrap-datetimepicker time plug-in in angular project

The above is the detailed content of Solve the problem of error when initializing the src attribute value of dynamically bound images in vue2.0. 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
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!