Vue 打开页面时就加载方法,例如查询

时间:2022-5-28    作者:老大夫    分类: JAVA


想要实现一打开页面就加载函数的效果,只需要添加created就可以了
把需要执行的方法先在methods中声明,然后再created中调用

var user = new Vue({
    el:"#user",
    data: {
        users:[],
    },
//*********************************
    created:function(){
        this.findAll();
    },
//*********************************
    methods:{
        findAll:function (){
            var that=this;
            axios.get("http://localhost:8080/user/findall").then(
                function (response){
                    that.users=response.data;
                },
                function (err){
                    console.log(err)
                }
            )
        },
    }
})

标签: vue html


扫描二维码,在手机上阅读

推荐阅读: