簡體   English   中英

所以我試圖在一個數組中獲取我的 axios 響應,但我不知道該怎么做

[英]So i'm trying to get my axios response in an array and I don't know how to do it

所以我試圖讓我的 axios 響應從 spring 引導頁面進入 vuejs 數組我不知道為什么,但顯然我不能在這里使用拆分。 我對 vue.js 還很陌生,所以請 go 對我放心。

Vue.js 代碼:

// JavaScript source code

new Vue({
    el: '#app',
    data() {
        return {
            urls: [],
            url: ""
        }
    },
    mounted() {
        axios
            .get("http://localhost:91/all/URL")
            .then(response => (this.url = response.data, this.urls = this.url.split(",")))
    }
})

HTML:

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <meta charset="utf-8" />
    <title>Home</title>
</head>
<body>
    <div id="app">
        <ul v-for="url in urls">
            <li> {{ url }} </li>
        </ul>
    </div>
    <script src="Script.js"></script>
</body>
</html>

控制台拋出以下錯誤:

Script.js:14 Uncaught (in promise) TypeError: this.urlfound.split is not a function
    at Script.js:14

變量名稱之間存在沖突,在模板中您有來自 v-for 的 url 並且在數據中定義了相同的 url。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM