index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <div ref="xspreadsheet" class="xspreadsheet"></div>
  3. </template>
  4. <style lang="scss" scoped>
  5. .xspreadsheet {
  6. position: absolute;
  7. top: 0;
  8. left: 0;
  9. width: 100%;
  10. height: 100%;
  11. display: flex;
  12. }
  13. </style>
  14. <script>
  15. import Spreadsheet from 'x-data-spreadsheet';
  16. import zhCN from 'x-data-spreadsheet/dist/locale/zh-cn';
  17. export default {
  18. name: "Sheet",
  19. props: {
  20. value: {
  21. type: Object,
  22. default: function () {
  23. return {}
  24. }
  25. },
  26. },
  27. data() {
  28. return {
  29. sheet: null,
  30. clientHeight: 0,
  31. clientWidth: 0,
  32. }
  33. },
  34. mounted() {
  35. Spreadsheet.locale('zh-cn', zhCN);
  36. //
  37. this.sheet = new Spreadsheet(this.$refs.xspreadsheet, {
  38. view: {
  39. height: () => {
  40. try {
  41. return this.clientHeight = this.$refs.xspreadsheet.clientHeight;
  42. }catch (e) {
  43. return this.clientHeight;
  44. }
  45. },
  46. width: () => {
  47. try {
  48. return this.clientWidth = this.$refs.xspreadsheet.clientWidth;
  49. }catch (e) {
  50. return this.clientWidth;
  51. }
  52. },
  53. },
  54. }).loadData(this.value).change(data => {
  55. this.$emit('input', data);
  56. });
  57. //
  58. this.sheet.validate()
  59. },
  60. }
  61. </script>