graph.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <div>
  3. <div :id="id" v-show="noshow">
  4. <slot></slot>
  5. </div>
  6. <div class="image" v-html="image"></div>
  7. </div>
  8. </template>
  9. <style scoped>
  10. .input {
  11. position: fixed;
  12. bottom: 0;
  13. left: 0;
  14. top: 56px;
  15. width: 100%;
  16. height: 100%;
  17. }
  18. .image {
  19. position: relative;
  20. }
  21. </style>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. id : 0 ,
  27. noshow : false ,
  28. dots: 'digraph "x"{\n 1->2\n 5->2;\n 1->3;\n 3->4;\n 4->1\n}'
  29. }
  30. } ,
  31. /*
  32. beforeMount() {
  33. var newScript = document.createElement("script");
  34. newScript.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/viz.js/1.3.0/viz.js' ) ;
  35. document.body.appendChild(newScript);
  36. } ,
  37. */
  38. created() {
  39. this.id = Math.floor(Math.random() * 5000);
  40. } ,
  41. mounted() {
  42. var slotdata = document.getElementById(this.id) ;
  43. console.log ( { slotdata , text : slotdata.outerText } ) ;
  44. this.dots = slotdata.outerText ;
  45. // this.image = Viz( slotdata.outerText , {format: 'svg'});
  46. } ,
  47. computed: {
  48. image : function(){
  49. var image = Viz(this.dots, {format: 'svg'});
  50. return image;
  51. }
  52. }
  53. }
  54. </script>