0
私は、vue.js、vue-resource、vue-mdl、およびGoogleマテリアルデザインライトを使用してWebアプリケーションを構築しています。 JSコンパイルは、lackvel elixirからwebpackを使用して実行されます。 このアプリケーションでは、残りのAPI(Django Rest Framework)から返された配列から各オブジェクトのテーブル行をレンダリングする必要があります。私はvue.jsを使用してコンテンツをレンダリングするために、HTML内部次のコードを行った:Vue.jsループがコンテンツをレンダリングしていない
<tr v-for="customer in customers">
<td class="mdl-data-table__cell--non-numeric">{{ customer.status }}</td>
<td class="mdl-data-table__cell--non-numeric">{{ customer.name }}</td>
<td class="mdl-data-table__cell--non-numeric">{{ customer.company }}</td>
<tr>
これは、テーブルの行として配列内のすべてのオブジェクトをレンダリングするべきです。私はまたこのようなテンプレートのタグで上記をラップしようとしました:
<template v-for="customer in customers">
<tr>
<td class="mdl-data-table__cell--non-numeric">{{ customer.status }}</td>
<td class="mdl-data-table__cell--non-numeric">{{ customer.name }}</td>
<td class="mdl-data-table__cell--non-numeric">{{ customer.company }}</td>
</tr>
</template>
これも変更されませんでした。 私はまた、vueインスタンスのready()関数の中で配列をハードコードしようとしましたが、これは役に立たなかったです。
window._ = require('lodash');
require('material-design-lite');
window.Vue = require('vue');
require('vue-resource');
var VueMdl = require('vue-mdl');
Vue.use(VueMdl.default);
const app = new Vue({
el:'body',
ready: function(){
//this.getCustomerList();
this.customers = [
{ name: "Peter", status: "true", company: "Company 1"},
{ name: "John", status: "false", company: "Company 2"}
]
},
data: {
customers: [],
response: null,
messages: []
},
methods: {
getCustomerList: function()
{
this.$http({url: '/api/customers/', method: 'GET'}).then(function(response){
//Success
this.customers = response.data
console.log(response.data)
},
function(response){
console.log(response)
})
}
}
})
これに上記の変更のいずれか変更されません:
window._ = require('lodash');
require('material-design-lite');
window.Vue = require('vue');
require('vue-resource');
var VueMdl = require('vue-mdl');
Vue.use(VueMdl.default);
const app = new Vue({
el:'body',
ready: function(){
//this.getCustomerList();
},
data: {
customers: [
{ name: "Peter", status: "true", company: "Company 1"},
{ name: "John", status: "false", company: "Company 2"}
],
response: null,
messages: []
},
methods: {
getCustomerList: function()
{
this.$http({url: '/api/customers/', method: 'GET'}).then(function(response){
//Success
this.customers = response.data
console.log(response.data)
},
function(response){
console.log(response)
})
}
}
})
私もちょうどGoogleのMDLクラスのいずれかが適用されていないプレーンなHTMLテーブルを作成しようとしましたが、これはありませんどんな結果も与えない。 コンソールにthis.customers
を記録すると、実際にデータが含まれていることが示されますが、レンダリングされていないためです。何故ですか?私は間違って何をしていますか?
コンソールにエラーがありますか?あなたの '
コンソールには何も載っていません。もちろん、 ''
答えて
コードのスニペットは、期待どおりに機能します。あなたが言及したライブラリへのCDN参照を追加しましたが、私は何もしません。私はこれをあなたがあなたの問題を再現する変更を見つけることができるかどうかを知るための出発点として提供します。ここで
出典
2016-08-25 17:25:26
通常、スクリプトが ''
'' 'にある場合、または' '' '' 'の一番下にある場合は違いはありません。あなたの例では、それらは '' '以下の回答を参照してください。コメントとしてコードを投稿することはできません。 –
@Kenneth_H投稿したマークアップのほとんどを使用するようにスニペットを更新しました。 :)しかし、それはまだすべての作品。 –
私はライブのコードを持っているよう
<table>
<body>
内側と底にすべてのスクリプトを持つと私の<head>
の完全な出力です。 お客様お客様
出典
2016-08-25 17:42:59
それは今働いているようです。 内部にapp.jsがありました
const app = new Vue({ el: 'body' })
何らかの理由で、私のメソッドが正常に機能しましたが、customer_list.js内に作成したものと競合していました。出典
2016-08-25 18:22:35
関連する問題