0
使用some help from StackOverflow當頁面加載和單擊按鈕時,我得到以下內容來運行我的loadData
。VueJS語法:在Promise中保存一個值
但是,頁面上的文本沒有更新。我的語法有點不對this.text = xhr.data
index.html:
<div id="app"></div>
app.js:
const Vue = window.Vue = require("vue");
Vue.prototype.$http = require("axios");
const App = require("./components/App.vue");
window.app = new Vue({
el: "#app",
render: h => h(App)
});
components/app.vue:
<template>
<div>
<h1>Test</h1>
<p>{{text}}</p>
<button @click="this.loadData">Reload</button>
</div>
</template>
<script>
export default {
mounted() {
this.loadData();
},
methods: {
loadData() {
this.$http.get("https://icanhazip.com")
// This fails
.then(xhr => this.text = xhr.data);
}
}
};
</script>
任何錯誤訊息? –
它看起來不像你有一個數據對象。只有數據對象中的屬性是被動的。 –