Vue.js的基础学习

Vue.js的基础网上很多,这里不记录

开始正式页面的开发

1.页面加载时请求数据

methods: {
                post() {
                    //发送post请求
                    this.$http.post('../../ashx/UploadReceipt.ashx', { "Type": "GetMyConsumptionScore", "MemberID": MemberID }, { emulateJSON: true }).then(function (res) {
                        var data = res.data;
                        this.receiptdata = data;
                    }, function () {
                        console.log('请求失败');
                    })
                }
            }

 

然后想要在页面加载时调用此方法还需要在mounted中调用

mounted: function () {
this.post();
},

js完整代码

new Vue({
            el: '.common-box',
            data: {
                title: "标题",
                receiptdata: null,
            },
            mounted: function () {
                this.post();
            },
            methods: {
                post() {
                    //发送get请求
                    this.$http.post('../../ashx/UploadReceipt.ashx', { "Type": "GetMyConsumptionScore", "MemberID": MemberID }, { emulateJSON: true }).then(function (res) {
                        var data = res.data;
                        this.receiptdata = data;
                    }, function () {
                        console.log('请求失败');
                    })
                },
                //返回事件
                Backclick() {
                    window.location.href = "../../my.html";
                },
                //列表点击事件
                Listclick(ID) {
                    //debugger;
                }
            }
        })

 

posted @ 2019-11-18 10:24  何以平天下  阅读(290)  评论(0编辑  收藏  举报