繁体   English   中英

在Vue.js中渲染自定义嵌套的html

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM