简体   繁体   English

Laravel Spark/Vue.js 中的 :class 属性是什么

[英]What are the :class Attributes in Laravel Spark/Vue.js

In Laravel spark, a <div/> enclosing a rendered form element might look like this在 Laravel spark 中,包含渲染表单元素的<div/>可能看起来像这样

<div class="form-group" :class="{'has-error': form.errors.has('name')}">

</div>

That is -- is has a :class attribute.也就是说 --is 有一个:class属性。 What is this?这是什么? I get the intent/behavior -- if the form.errors.hash('name') call returns true (with form being a SparkForm set on the enclosing component) then the div will have an has-error class.我得到了意图/行为——如果form.errors.hash('name')调用返回 true( form是在封闭组件上设置的SparkForm ),那么 div 将有一个has-error类。 However, what makes :class work?但是,是什么让:class工作? My first assumption was it's a Vue.js thing, but if I read the Vue docs on class and style bindings , it (seems like?) Vue.js expects an attribute named v-bind:class我的第一个假设是它是 Vue.js 的东西,但是如果我阅读Vue 文档关于 class 和 style bindings ,它(看起来像?)Vue.js 需要一个名为v-bind:class的属性

<div class="form-group" v-bind:class="{'has-error': form.errors.has('name')}">

</div>

So what makes :class work?那么是什么让:class工作? Is this a Vue.js provided short cut?这是 Vue.js 提供的捷径吗? (if so, is it documented somewhere?). (如果是这样,它是否记录在某处?)。

Is this some patented Laravel syntactic sugar to make writing templates a bit less verbose?这是一些获得专利的 Laravel 语法糖,可以让编写模板不那么冗长吗? If so, where's this implemented?如果是这样,这是在哪里实现的?

Is it some third thing?这是第三件事吗?

So what makes :class work?那么是什么让 :class 工作? Is this a Vue.js provided short cut?这是 Vue.js 提供的捷径吗? (if so, is it documented somewhere?). (如果是这样,它是否记录在某处?)。

Yes , Its a Vuejs Shorthand是的,它是一个 Vuejs 简写

document: https://v2.vuejs.org/v2/guide/syntax.html#Shorthands文档: https ://v2.vuejs.org/v2/guide/syntax.html#Shorthands

The v- prefix serves as a visual cue for identifying Vue-specific attributes in your templates. v-前缀用作标识模板中特定于 Vue 的属性的视觉提示。 This is useful when you are using Vue.js to apply dynamic behavior to some existing markup, but can feel verbose for some frequently used directives.当您使用 Vue.js 将动态行为应用于某些现有标记时,这很有用,但对于某些常用指令可能会感到冗长。 At the same time, the need for the v- prefix becomes less important when you are building an SPA where Vue.js manages every template.同时,当您构建一个由 Vue.js 管理每个模板的 SPA 时,对v-前缀的需求变得不那么重要了。 Therefore, Vue.js provides special shorthands for two of the most often used directives, v-bind and v-on :因此,Vue.js 为两个最常用的指令v-bindv-on提供了特殊的简写:

there is no diffrence between之间没有区别

:class="{'has-error': form.errors.has('name')}

and

v-bind:class="{'has-error': form.errors.has('name')}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM