简体   繁体   English

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

[英]Rendering custom nested html in Vue.js

I'm moving a site from AngularJS 1.x that relies heavily on the $compile service (which is no longer available in Angular 2.x. In the application I have a directive that looks something like this <myDir elemId="someRestEndPointID"></myDir> and does the following: 我从AngularJS 1.x移动了一个站点,该站点在很大程度上依赖于$ compile服务(在Angular 2.x中不再可用。在应用程序中,我有一条指令看起来像这样<myDir elemId="someRestEndPointID"></myDir>并执行以下操作:

1) A http call is made and the response returns a string that contains a directive <myDir elemId="someRestEndPointID"></myDir> 1)进行http调用,并且响应返回包含指令<myDir elemId="someRestEndPointID"></myDir>

2) A call is made to the server to for /someRestEndPointID 2)呼叫服务器以/ someRestEndPointID

3) Angular gets the content and renders and looks for another <myDir> tag 3)Angular获取内容并渲染并寻找另一个<myDir>标签

4) the process is repeated (recursive) 4)重复该过程(递归)

I have not yet found something that does this for our new framework Vue.js. 我还没有为我们的新框架Vue.js做到这一点的东西。 Is there a similar feature or library that would achieve this logic in Vue.js? 在Vue.js中是否有类似的功能或库可以实现此逻辑?

That seems like a convoluted way to work and I wouldn't follow that pattern. 这似乎是一种复杂的工作方式,我不会遵循这种模式。 Why not create a component that takes an endpoint as a property <your-component endpoint="https://example.org/"></your-component> and then component will do the call inside the create method? 为什么不创建一个将端点作为属性<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