【发布时间】:2017-08-22 22:11:26
【问题描述】:
我的 vue 组件是这样的:
<template>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false" :title="...">
...
<span v-if="totalNotif > 0" class="badge" id="total-notif">{{ totalNotif }}</span>
</a>
</li>
</template>
<script>
...
export default {
mounted() {
this.initialMount()
},
...
computed: {
...mapGetters([
'totalNotif'
])
},
methods: {
initialMount() {
Echo.private('App.User.' + window.Laravel.authUser.id).notification((notification) => {
const totalNotif = $('#total-notif').text()
const totalNotifNew = parseInt(totalNotif) + 1
$('#total-notif').text(totalNotifNew )
})
},
}
}
</script>
有效
但是,它仍然使用 jquery 来获取和更新 span 上的文本
如何使用 vue.js 2 做到这一点?
我阅读了一些参考资料,它使用watch。但我仍然对使用它感到困惑
【问题讨论】:
标签: jquery vue.js vuejs2 vue-component