首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >有没有办法在Vue.js中动态插入点击事件?

有没有办法在Vue.js中动态插入点击事件?
EN

Stack Overflow用户
提问于 2018-06-05 04:19:29
回答 2查看 2K关注 0票数 4

试图实现将一些计算方法插入到仅依赖于移动视口的元素上。以下是我正在使用的基本要点:

代码语言:javascript
复制
<a class="nav-link float-left p-x-y-16" v-bind:class={active:isCurrentTopicId(t.id)} @click="onTopicClicked($event, m, t)" href="#">{{t.title}}</a>

<script>

export default {
    data() {
        return {
            isClosed: false
        }
    },
    computed: {
        toggleMenu() {
            return {
                isClosed: this.isClosed
            }
        }
    },
    watch: {
        browserWidth(prevWidth, newWidth) {
            console.log('width changed from ' + newWidth + ' to ' + prevWidth);
    },
    mounted() {
        var that = this;
        this.$nextTick(function() {
            window.addEventListener('resize', function(e) {
                that.browserWidth = window.innerWidth;
                if(that.browserWidth > 824) {
                    console.log('Desktop View');
                } else {
                    console.log('Mobile View');
                }
            })
        })
    }
}
</script>

我想尝试使用resize事件来确定浏览器的宽度,这样我就可以将计算出的函数动态地插入到该<a>标记上

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50688176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档