Home  >  Article  >  php教程  >  Analysis of the causes of syntax errors in binding HTML class arrays in Vue.js

Analysis of the causes of syntax errors in binding HTML class arrays in Vue.js

高洛峰
高洛峰Original
2016-12-09 15:58:161377browse

Vue.js has a syntax error in binding HTML class array, the details are as follows:

I found an error like this on the official website tutorial yesterday, see the picture below

http://cn.vuejs.org/guide/class -and-style.html

This is a bit cumbersome to write when there are multiple conditional classes. In 1.0.19+, object syntax can be used in array syntax:

If written like this, it can be executed successfully, but there is an error

data: {
classA: 'class-a',
classB: 'class-b',
classC: 'class-c',
isB: true,
isC: false
}
<div :class="[classA, { classB: isB, classC: isC }]">

is rendered as:

<div class="class-a classB">

If it is short Class-b such as horizontal characters is unsuccessful, so we still need to use standard object syntax with quotation marks

<div :class="[classA, { &#39;class-b&#39;: isB, &#39;class-c&#39;: isC }]">

Rendered as:

<div class="class-a class-b">


Statement:
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