【问题标题】:How to replace div with html onclick using Vue js?如何使用 Vue js 将 div 替换为 html onclick?
【发布时间】:2020-05-14 21:31:32
【问题描述】:

我在 div 中有一个响应按钮,并附有一个 Modal。

<div v-if="notification ? notification.type === 'App\\Notifications\\InterviewRequestEmployerReply' : ''">
    <button class="btn btn-primary btn-sm text-right" @click="editNotificationRequest(notification)">Respond</button>
</div>

如果用户单击“确认采访”按钮,则响应按钮应替换为此 &lt;strong class="text-success"&gt;Confirmed&lt;/strong&gt;

我有一个名为createConfirmedInterviewRequest() 的方法,当用户单击“确认面试”按钮时会调用该方法。所以我想创建一个可以更改内容的方法,然后我会在我的createConfirmedInterviewRequest() 方法中调用该方法,但我不知道如何创建此方法或如何做到这一点。

附件是我的页面的屏幕截图,其中包含响应按钮和模式。

如何使用 Vue 更改 div 的内容?

更新:

data() {
            return {
                notifications: {
                    noti: false
                },
            }
},

computed:{
            computedConfirm(){
                return this.notifications.noti ? true:false;
            }
        },

methods: {
            confirmProcess(){
                this.notifications.noti = true;
            },
}

我的方法:

createConfirmedInterviewRequest: async function() {
   this.confirmProcess(`data`);
}

带按钮的模态:

<b-button type="submit" variant="success" @click="confirmProcess(`data`)" class="mr-2 mt-2">
   <i class="fas fa-handshake"></i>Confirm Interview
</b-button>

我想消失的回复按钮并替换为&lt;strong class="text-success"&gt;Confirmed&lt;/strong&gt;

<div v-if="notification ? notification.type === 'App\\Notifications\\InterviewRequestEmployerReply' : ''">
                        <button class="btn btn-primary btn-sm text-right" @click="editNotificationRequest(notification)" v-if="!computedConfirm">Respond</button>

如果您需要了解通知中的数据属性,请告诉我。

【问题讨论】:

    标签: vue.js


    【解决方案1】:

    使用v-ifv-else,条件会在你的editNotificationRequest方法中改变:

    <div v-if="notification ? notification.type === 'App\\Notifications\\InterviewRequestEmployerReply' : ''">
        <button v-if="clickConfirmed" class="btn btn-primary btn-sm text-right" @click="editNotificationRequest(notification)">Respond</button>
        <strong v-else class="text-success">Confirmed</strong>
    </div>
    

    【讨论】:

    • 我是否将 clickConfirmed 添加到 data() 或者这应该是一种方法?
    • 更容易使用数据属性,虽然它可以在您确认的值上计算属性,然后您不需要手动更改它
    • 我的代码正在使用 service.js 文件来发出我的 axios 请求,并且我正在使用 v-for 来显示数据库中的所有数据。我不确定你到底需要什么...
    • 如果你给我看一个例子,你有一个可以做任何事情的方法,然后在那个方法中,另一个方法可以做我所要求的。数据可以是任何东西......
    • 数据属性codepen.io/MNSY22/pen/BaoOmGR的示例实现
    猜你喜欢
    • 2020-06-15
    • 2020-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多