首页 > 解决方案 > 如何更正vuejs中的网址?

问题描述

我使用 axios 向http://localhost:8000/api/residence发送一个请求,之后我在我的页面中显示结果,当我想通过单击按钮移动到另一个页面时,我得到了错误的 url(当前 url + url请求 axios) 像这样**( http://localhost:8080/http://127.0.0.1:8000/residence/6 )** 我该如何解决这个问题。

<div class="col-md-6 col-lg-4" v-for="r in res.data">
   <div class="card-body">
     <h4 class="card-title">{{r.nom}} <br></h4>
   </div>
   <div>
    <router-link :to="'/residence/' + r.id" class="btn btn-outline-primary 
btn-sm btt">Full info</router-link> 
   </div>           
 </div>

axios.get('http://127.0.0.1:8000/api/residence?page=' + page)
.then(response => {   
  this.res = response.data.data;
 });

标签: laravelapivue.jsaxios

解决方案


表格 :

<form @submit.prevent="addproperty()">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label>Property Title</label>
                                        <input type="text" name="property-title" class="form-control" placeholder="Property Title"required v-model="property_title">
                                    </div>
                                </div>

        <button type="submit" class="btn btn-success">Submit</button>
                        </form>

网址:

<script>
    export default {
        data() {
            return {
                property_title:null,

            }
        },
        methods: {
            addproperty() {

            axios.post('addproperty',{title: this.property_title});
                this.$router.push('/properties_list')
            },

        },
    }

</script>

推荐阅读