Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

vue.js - VueJS Component, can't override class

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.

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.

Instance:

<delete-button buttonClass="is-info" csrf="{{ csrf_token() }}" action="redirects/delete-all"
               text="Delete All" body="This will delete ALL redirects"></delete-button>

Component:

<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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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" ...

See https://vuejs.org/v2/guide/components-props.html#Prop-Casing-camelCase-vs-kebab-case

HTML attribute names are case-insensitive, so browsers will interpret any uppercase characters as lowercase. That means when you’re using in-DOM templates, camelCased prop names need to use their kebab-cased (hyphen-delimited) equivalents

FYI, single-file components do use "in-DOM templates".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...