vue中,在页面加载完成后,JS再写入带@click的HTML代码,此时如何让@click响应点击事件?

vue中,在页面加载完成后,JS再写入带@click的HTML代码,此时如何让@click响应点击事件?,第1张

直接在methods方法里面写你的点击事件函数

html

<template v-for="(item, index) in questionnaireList">

    <div class="questionnaire-section" @click="onSection(item.id)">

        <div class="title">{{item.title}}</div>

    </div>

</template>

js

var app = new Vue({

    el: '#app',

    data: {

        questionnaireList: [], //定义一个空数组

        currentPage: 1, //当前页

    },

    //加载完后自动执行

    mounted:function(){

        var that = this

        that.questionnaireData() //调用方法

    },

    methods: {

        questionnaireData:function () {

            var that = this

            $.ajax({

                url: url + "questionnaire",

                type: "GET",

                data:{

                    currPage: that.currentPage

                },

                success:function (res) {

                    res.data.questions.map(function (item,index) {

                        that.questionnaireList.push(item)

                    })

                }

            })

        },

        

        //绑定的点击事件

        onSection:function (id) {

            console.log("你当前点击的栏目对应id是: " + id)

        },

    }

})

第一种方式 reload

一、在根文件 app.vue文件中配置

二、在需要引用重置的页面中添加

大功高成!!!

补充:(推荐使用第一种 方式 reload,体验度好,无空白页面)

以下两种方式也是实现重置刷新的功能

缺点:相当于按ctrl+F5 强制刷新那种,整个页面重新加载,会出现一个瞬间的空白页面,体验度不好

在 el-table 标签里面加入

在 data 里面添加对应的 pictLoading 属性,并设置为false,当加载数据的时候设置为true,加载完数据后设置为false


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11595667.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存