Vuejs动态改变道具

时间:2018-05-18 09:59:30

标签: vue.js

我有一个组件上传,它传递类型到Alert.vue这是有效的。我想要的只是将危险,警告或成功传递给alert.vue并在那里连续上课。

像这样:

<alert :loading="false" loadingtext="" type="danger" :alerttext="errortypes[file.error]" v-if="file.error">{{file.error}}</alert>

我如何实现?

Upload.vue:

<div v-for="(file, index) in files" :key="file.id">
    <span v-if="selectedfile">{{file.name}}</span>
    <alert :loading="false" loadingtext="" type="alert alert-danger fade in alert-dismissible" :alerttext="errortypes[file.error]" v-if="file.error">{{file.error}}</alert>
    <alert :loading="false" loadingtext="" type="alert alert-success fade in alert-dismissible" :alerttext="alertfilesuccessuploaded" v-else-if="file.success"></alert>
    <alert :loading="false" loadingtext="" type="alert alert-warning fade in alert-dismissible" :alerttext="loadingtext" v-else-if="file.active"></alert>
</div>

Alert.vue:

<template>
    <div :class="type" role="alert">
        <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
        <span v-html="alerttext"></span>
        <loading v-show="loading" :loadingdata="loadingtext"></loading>
    </div>
</template>
<script>
    export default {
        props: {
            type: String,
            alerttext: String,
            loading: Boolean,
            loadingtext: String
        },
        created() {
            this.newtype = 'alert alert-' + this.type + ' fade in alert-dismissible';
        },
        data: function () {
            return {
                newtype:''
            }
        },
    }
</script>

1 个答案:

答案 0 :(得分:0)

找到解决方案:

<alert :loading="false" loadingtext="" type="danger" v-if="file.error">{{file.error}}</alert>

<div v-bind:class="setType(type)" role="alert">

methods: {
    setType(type) {
        return 'alert alert-' + type + ' fade in alert-dismissible';
    }
},