问题描述
我正在尝试覆盖我的 VueJS 组件的某个实例,但是由于某种原因,该组件仍在使用默认值.
i'm trying to over-ride a certain instance of my VueJS Component, however for some reason the component is still using the default value.
我试图覆盖的值是 buttonClass
.其他道具似乎工作正常,所以不太确定为什么这个道具不起作用.
The value i'm trying to over-ride is the buttonClass
. The other props seem to work fine, so not too sure as to why this one isn't working.
实例:
<delete-button buttonClass="is-info" csrf="{{ csrf_token() }}" action="redirects/delete-all"
text="Delete All" body="This will delete ALL redirects"></delete-button>
组件:
<template>
<form v-bind:action="action" method="post" @submit.prevent="confirm($event)">
<input type="hidden" name="_token" v-model="csrf">
<input type="hidden" v-model="id" name="id-value">
<button type="submit" :class="['button is-link', buttonClass]">
<i class="fas fa-trash-alt"></i>
<span v-html="text"></span>
</button>
</form>
</template>
<script>
export default {
props: {
'id': {},
'csrf': {},
'action': {},
'buttonClass': {
default: 'is-danger'
},
'text': {
default: 'Delete'
},
'title': {
default: 'Are you sure?'
},
'body': {
default: ''
}
}
// etc
}
</script>
推荐答案
根据这一切的组合方式,模板中的 props 有时需要采用 kebab-cased,即
Depending on how this is all put together, props in the template are sometimes required to be kebab-cased, ie
<delete-button button-class="is-info" ...
参见 https://vuejs.org/v2/guide/components-props.html#Prop-Casing-camelCase-vs-kebab-case
HTML 属性名称不区分大小写,因此浏览器会将任何大写字符解释为小写.这意味着当你使用 in-DOM 模板时,camelCased prop 名称需要使用它们的 kebab-cased(连字符分隔)等价物
仅供参考,单文件组件确实使用in-DOM 模板".
FYI, single-file components do use "in-DOM templates".
这篇关于VueJS 组件,不能覆盖类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!