1
我试图从api数据呈现或加载组件。为了解释更多,我们假设我有测试组件,我直接将其注入到父组件中,它可以工作。但是当我试图在数据库中保存组件标记并运行ajax调用时,我的组件标记显示但不起作用,或者更确切地说是加载/呈现。请帮忙。从我的APIVue.js - 从Ajax调用加载组件
返回:
{
"_id": "59411b05015ec22b5bcf814b",
"createdAt": "2017-06-14T11:16:21.662Z",
"updatedAt": "2017-06-14T12:41:28.069Z",
"name": "Home",
"content": "<test-comp></test-comp>",
"slug": "/",
"navName": "Home",
"__v": 0,
"landing": true,
"published": false
}
我父组件:
<template>
<div>
<test-comp></test-comp> // This works
<div v-html="page.content"></div> // But this doesn't :(
</div>
</template>
<script>
import { Api as defApi } from 'shared';
import test from './testComp';
export default {
data:() => ({
page: {}
}),
created() {
defApi.get('api/pages/landing')
.then((res) => {
this.page = res.data.body;
});
},
components: {
testComp: test
}
};
</script>
非常感谢..它确实像一个魅力工作。 –