[英]Rendering custom nested html in Vue.js
我從AngularJS 1.x移動了一個站點,該站點在很大程度上依賴於$ compile服務(在Angular 2.x中不再可用。在應用程序中,我有一條指令看起來像這樣<myDir elemId="someRestEndPointID"></myDir>
並執行以下操作:
1)進行http調用,並且響應返回包含指令<myDir elemId="someRestEndPointID"></myDir>
2)呼叫服務器以/ someRestEndPointID
3)Angular獲取內容並渲染並尋找另一個<myDir>
標簽
4)重復該過程(遞歸)
我還沒有為我們的新框架Vue.js做到這一點的東西。 在Vue.js中是否有類似的功能或庫可以實現此邏輯?
這似乎是一種復雜的工作方式,我不會遵循這種模式。 為什么不創建一個將端點作為屬性<your-component endpoint="https://example.org/"></your-component>
,然后該組件將在create
方法內進行調用?
<template>
<div>
<img src="loading.jpg" v-show="loading" />
<!-- Content here -->
{{content}}
</div>
</template>
<script>
export default {
props: ['endpoint'],
data() {
return {
loading: true,
content: null
};
},
created() {
this.$http.get(this.endpoint).then(resp => {
this.content = resp.body;
this.loading = false;
});
}
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.