Popular blog tags

axios参数传递(1)-用x-www-form-urlencoded传递请求参数

Published

Content-Type:x-www-form-urlencoded

<script>

            const apiUrl = "http://api.iaspnetcore.com";
            const ApiKey = "your_api_key";

            function buildUrl(url) {
                return apiUrl + url
            }



            var vm = new Vue({
                el: '#app',
                data: {


                    search: {
                        password: null,
                        id: '@Model.Id.ToString()'
                    },
                    loading: true,
                    title: null,
                    body:null,
                    post: null,
                    error: null,
                    results: [],



                },



                mounted() {

                },



                methods: {




                    //post  方法
                    Authenticate: function () {
                        //设置起始记录

                        this.loading = true;

                        const params = new URLSearchParams();
                        params.append('id', this.search.id);
                        params.append('password', this.search.password);

                      //  axios.post("/blog/Authenticate", vm.search)
                        axios.post("/blog/Authenticate", params)
                            .then((response) => {

                                this.results = response.data;
                                this.title = response.data.title;
                                this.body = response.data.body;
                                this.error = response.data.error;
                                this.loading = false;

                                console.log(response);
                            })
                            .catch(function (error) {
                                alert(error.message);
                            });
                    },




                }
            })
        </script>