加载中...

Clipboard


实例代码

  1. <template>
  2. <scroller>
  3. <wxc-panel title="Clipboard" type="primary">
  4. <wxc-panel title="Copy to clipboard5">
  5. <text style="line-height:40px;font-size:28px">{{textToCopy}}</text>
  6. <wxc-button type="info" size="middle" value="Copy" onclick="{{doCopy}}"></wxc-button>
  7. </wxc-panel>
  8.  
  9. <wxc-panel title="Paste from clipboard">
  10. <text style="line-height:40px;font-size:28px">{{textFromPaste}}</text>
  11. <wxc-button type="info" size="middle" value="Paste" onclick="{{doPaste}}"></wxc-button>
  12. </wxc-panel>
  13.  
  14. <wxc-panel title="Result">
  15. <wxc-tip style="margin-bottom: 20px;" value="{{tips}}"></wxc-tip>
  16. </wxc-panel>
  17.  
  18. </wxc-panel>
  19. </scroller>
  20. </template>
  21.  
  22. <script>
  23. require('weex-components');
  24.  
  25. module.exports = {
  26. data: {
  27. textToCopy : '',
  28. textFromPaste: '',
  29. tips : '',
  30. },
  31. ready : function() {
  32. this.tips = "1. Just click COPY button. It will auto generate a string with random text, and copy to system clipboard. \n 2. do copy in another app, then come back and click PASTE button."
  33. },
  34. methods: {
  35. clicked: function() {
  36. var $modal = require('@weex-module/modal');
  37. $modal.toast({'message': 'clicked!', duration: 0.5});
  38. },
  39.  
  40. doCopy: function() {
  41. var self = this
  42. var textToCopy = "autoGenerateTextToCopy" + Math.random();
  43.  
  44. var clipboard = require('@weex-module/clipboard');
  45. clipboard.setString(textToCopy);
  46.  
  47. self.textToCopy = textToCopy;
  48. self.tips = "copy done. Now system clipboard has string of '" + textToCopy + "', try PASTE button, or paste in another app."
  49. },
  50.  
  51. doPaste: function() {
  52. var clipboard = require('@weex-module/clipboard');
  53. var me = this;
  54. clipboard.getString(function(ret) {
  55. console.log("paste result is " + JSON.stringify(ret));
  56.  
  57. me.textFromPaste = JSON.stringify(ret);
  58. me.tips = "Paste done. Only support native(Android/iOS) NOW. according to security reason, paste in html5 is not supported.";
  59. });
  60. }
  61.  
  62. }
  63.  
  64. };
  65. </script>

还没有评论.