• <bdo id='BMu5K'></bdo><ul id='BMu5K'></ul>
      <legend id='BMu5K'><style id='BMu5K'><dir id='BMu5K'><q id='BMu5K'></q></dir></style></legend>
    1. <i id='BMu5K'><tr id='BMu5K'><dt id='BMu5K'><q id='BMu5K'><span id='BMu5K'><b id='BMu5K'><form id='BMu5K'><ins id='BMu5K'></ins><ul id='BMu5K'></ul><sub id='BMu5K'></sub></form><legend id='BMu5K'></legend><bdo id='BMu5K'><pre id='BMu5K'><center id='BMu5K'></center></pre></bdo></b><th id='BMu5K'></th></span></q></dt></tr></i><div id='BMu5K'><tfoot id='BMu5K'></tfoot><dl id='BMu5K'><fieldset id='BMu5K'></fieldset></dl></div>

    2. <small id='BMu5K'></small><noframes id='BMu5K'>

      <tfoot id='BMu5K'></tfoot>
    3. VueJS - 如何使用 ajax 调用的结果动态初始化模板

      时间:2024-04-19

    4. <i id='hfaeK'><tr id='hfaeK'><dt id='hfaeK'><q id='hfaeK'><span id='hfaeK'><b id='hfaeK'><form id='hfaeK'><ins id='hfaeK'></ins><ul id='hfaeK'></ul><sub id='hfaeK'></sub></form><legend id='hfaeK'></legend><bdo id='hfaeK'><pre id='hfaeK'><center id='hfaeK'></center></pre></bdo></b><th id='hfaeK'></th></span></q></dt></tr></i><div id='hfaeK'><tfoot id='hfaeK'></tfoot><dl id='hfaeK'><fieldset id='hfaeK'></fieldset></dl></div>

          <tbody id='hfaeK'></tbody>
        <tfoot id='hfaeK'></tfoot>

        • <legend id='hfaeK'><style id='hfaeK'><dir id='hfaeK'><q id='hfaeK'></q></dir></style></legend>
          • <small id='hfaeK'></small><noframes id='hfaeK'>

              • <bdo id='hfaeK'></bdo><ul id='hfaeK'></ul>
                本文介绍了VueJS - 如何使用 ajax 调用的结果动态初始化模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想为 VueJS 组件动态加载 template.我想使用 jQuery 进行 AJAX 调用,无论服务器返回什么都应该是 VueJS 组件的 template.这是删除了 AJAX 调用的代码的简化版本,因为它与数据的来源无关:

                I want to load the template for a VueJS component dynamically. I'd like to make an AJAX call using jQuery, and whatever the server returns should be the template of the VueJS component. Here's a simplified version of the code with the AJAX call removed since it's irrelevant where the data is coming from:

                BoardFeed = Vue.extend
                    template: '<div>This should be replaced</div>'
                    data: ->
                            return items: null
                    created: ->
                        @template = "<div>Template returned from server, what I really want</div>"
                

                在上面的示例中,我使用了 created 钩子,我认为这是适合这个,但新模板永远不会渲染,只会渲染旧模板.

                In the above example I'm using the created hook which I thought would be suitable for this, but the newer template is never rendered, only the older one.

                有可能实现吗?

                推荐答案

                您可以在模板中使用 v-partial.当你加载了部分,你可以通过 Vue.partial() 注册它.然后替换 {{ partial }} 值,从而呈现新的部分.

                You could use v-partial in your template. And when you've loaded the partial, you can register it via Vue.partial(). The {{ partial }} value is then replaced, thus rendering the new partial.

                BoardFeed = Vue.extend
                    template: '<div v-partial="{{ partial }}">This should be replaced</div>'
                    partials: {"beforeLoad": "<div>This should be replaced</div>"}
                    data: ->
                            return {items: null, partial: "beforeLoad"}
                    created: ->
                        Vue.partial("afterLoad", "<div>Template returned from server, what I really want</div>")
                        @partial = "afterLoad"
                

                (请原谅任何咖啡脚本错误,我不是很熟悉)

                (and excuse any coffee-script errors, I'm not very familiar with it)

                这篇关于VueJS - 如何使用 ajax 调用的结果动态初始化模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:编写 CoffeeScript 时有没有办法捕捉错别字 下一篇:“桶装填"Javascript 或咖啡脚本中的算法

                相关文章

              • <tfoot id='CfrCU'></tfoot>

                1. <small id='CfrCU'></small><noframes id='CfrCU'>

                  <legend id='CfrCU'><style id='CfrCU'><dir id='CfrCU'><q id='CfrCU'></q></dir></style></legend>
                2. <i id='CfrCU'><tr id='CfrCU'><dt id='CfrCU'><q id='CfrCU'><span id='CfrCU'><b id='CfrCU'><form id='CfrCU'><ins id='CfrCU'></ins><ul id='CfrCU'></ul><sub id='CfrCU'></sub></form><legend id='CfrCU'></legend><bdo id='CfrCU'><pre id='CfrCU'><center id='CfrCU'></center></pre></bdo></b><th id='CfrCU'></th></span></q></dt></tr></i><div id='CfrCU'><tfoot id='CfrCU'></tfoot><dl id='CfrCU'><fieldset id='CfrCU'></fieldset></dl></div>
                  • <bdo id='CfrCU'></bdo><ul id='CfrCU'></ul>