javascript - vue+wangEdit的無法讀取未定義的屬性“選單”
想做個後台輪子方便以後開發用,中間表單這塊的富文本編輯想集成wangEdit進來,用了vue vue-router,打算是做成獨立模組的,前端調用組件後請求後端提供的資料介面來渲染出想要的頁面,所以頁面內這麼寫了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <code><template>
<p>
<p v- for = "item in items" >
<p v- if = "item.type=='editor'" >
<label>{{ item.title }}</label>
<p id= "editor" style= "height:400px;max-height:500px;" >
{{ item.model }}
</p>
</p>
<p v- if = "item.type=='input'" >
<el-input v-model= "item.model" placeholder= "请输入内容" ></el-input>
</p>
</p>
</p>
</template></code>
|
然後在vue的mounted裡寫了:
1 2 3 4 5 6 7 | <code>mounted() {
axios.get( 'shop/pageData' ).then((res)=>{
this.items = res.data.data;
var editor = new wangEditor( 'editor' );
editor.create();
});
}</code>
|
然後渲染不出來,報錯
Uncaught (in promise) TypeError: Cannot read property 'menus' of undefined
沒怎麼做過前端和用vue,請問各位:
1.vue 配合後端如何更好的獲取數據,直接在頁面調用組件的時候json_encode($data)//我用的php做後端
還是在元件被呼叫時來axios請求取得資料
2.開始以為是時間差問題,以為資料沒有請求到就去渲染才出的問題,所以試了一下在created(){}部分去請求數據,將值賦給this.data,然後在mounted(){}去呼叫的時候發現this.data沒有值,這是啥呢?