How to add copy to clipboard functionality in vuejs with prismjs?

百般思念 提交于 2019-12-23 23:25:52

问题


I am displaying Html syntax using vue-prism-component (https://www.npmjs.com/package/vue-prism-component). Now I want to add a button that should copy the code. So far, I have found a library vue-clipboard2 (https://www.npmjs.com/package/vue-clipboard2) in this they are getting text from an input tag. How I would select the syntax of Html generated by vue-prism-component on a click of button.


回答1:


Prism has some documentation for implementing such feature

https://prismjs.com/plugins/copy-to-clipboard/

Here is the example code for copying code from vue-prism-component

[Codepen] https://codepen.io/wilbo/pen/xRVLOj

You need to add this dependency of clipboard https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.5.12/clipboard.min.js

another codepen example which is not in vue but just to get idea

[Codepen] https://codepen.io/drhodes/pen/NAOgpG


来源:https://stackoverflow.com/questions/58092562/how-to-add-copy-to-clipboard-functionality-in-vuejs-with-prismjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!