html>
<head>
<title>Vue App</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.3/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/0.12.7/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue-resource/0.1.13/vue-resource.min.js"></script>
</head>
<body>
<!--
<h1>
<a href="http://localhost:1337/"> Home Page</a>
</h1>
<h1>
<a href="http://localhost:1337/form"> Form Page</a>
</h1>
-->
<div id="my_view">
<p>{{ responseOptions| json }}</p>
<br />
<p>{{ origin | json }}</p>
</div>
<script>
new Vue({
el: '#my_view',
data: {
origin: ''
},
//it is showing an empty array. It's not returning any data.
//leave name:"name" out and it returns the whole object?
// example from https://github.com/pagekit/vue- resource/blob/master/docs/http.md
ready: function() {
var resource = this.$resource('https://jsonplaceholder.typicode.com/users');
resource.get({name: "name"}).then((response) => {
this.$set('responseOptions', response.status)
this.$set('origin', response)
});
}
})
</script>
</body>
</html>
你好, 試圖找出api的vue-resource $ http訪問是如何工作的。所以創建了這個基本頁面,當我將它加載到瀏覽器時,我得到的只是一個空數組。我遵循官方頁面上發佈的指示(https://github.com/pagekit/vue-resource/blob/master/docs/http.md)
我能夠在頁面上顯示response.status,因此腳本正在通信,但數據根本不顯示。如果您訪問該頁面(https://jsonplaceholder.typicode.com/users),那麼數據就在那裏。
我在做什麼錯? 請指教...
如果你正在使用Vue 2,準備好的鉤子是depracated - 使用掛載,或者更好的選擇是去創建。 又是什麼'this。$ resource'?你應該定義'this。$ http' –