index.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. }
  31. },
  32. mounted() {
  33. Spreadsheet.locale('zh-cn', zhCN);
  34. //
  35. this.sheet = new Spreadsheet(this.$refs.xspreadsheet, {
  36. view: {
  37. height: () => this.$refs.xspreadsheet.clientHeight,
  38. width: () => this.$refs.xspreadsheet.clientWidth,
  39. },
  40. }).loadData(this.value).change(data => {
  41. this.$emit('input', data);
  42. });
  43. //
  44. this.sheet.validate()
  45. },
  46. }
  47. </script>