Vue.js打印原始HTML和调用组件方法 [英] Vue.js print raw html and call component methods

查看:200
本文介绍了Vue.js打印原始HTML和调用组件方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从ajax请求中动态加载html内容.该html有一些按钮,例如

I am dynamically loading the html content from an ajax request. This html has some buttons like

<button @click="someComponentMethod">Add</button>

如您所见,我正在尝试调用组件方法.但是它不起作用.

As you can see I am trying to call components methods. But Its not working.

我认为代替@click html的默认属性"onclick"应该起作用.但这只会识别全局范围内定义的功能.有人可以指导我如何从核心javascript(即使用"onclick")调用组件的功能.

I think instead of @click html's default attribute "onclick" should work. But this will only recognize the function that are defined in global scope. Can someone guide me how I can call component's function from core javascript i.e using "onclick".

更新

好!我知道v-html不会编译该html.但是你们能告诉我如何从javascript中调用组件方法吗(即,不在组件范围内).这样,我就可以使用onclick="JAVASCRIPT_CODE_TO_EXECUTE_METHOD".

Ok! I got it that v-html will not compile that html. But can you guys tell me how can I call component method from javascript (i.e outside of component scope). In this way I will be able to use onclick="JAVASCRIPT_CODE_TO_EXECUTE_METHOD".

推荐答案

我最终没有以html格式保存组件,而是加载了html.该组件具有存储html字符串的template属性.这样,我就可以在数据库中存储和加载组件,并且可以正常工作.

Instead of loading html I end up saving component in JSON format. This component has a template property that stores the html string. In this way I am able to store and load component to and from database and it works without any issue.

这篇关于Vue.js打印原始HTML和调用组件方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆