DynamicImport.vue 928 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <!-- 动态加载 -->
  2. <template>
  3. <div class="container-fluid">
  4. <div class="row">
  5. <button
  6. class="btn btn-success"
  7. @click="change1"
  8. >
  9. 动态加载
  10. </button>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. components: {
  17. },
  18. data: function () {
  19. return {
  20. };
  21. },
  22. methods: {
  23. change: function () {
  24. let filename = 'DynamicImport.js';
  25. import('./' + filename).then(({ counter, incCounter }) => {
  26. console.log(counter); //3
  27. incCounter();
  28. console.log(counter); //3
  29. });
  30. },
  31. change1: function () {
  32. let filename = null;
  33. for(let index = 1; index < 2; index ++){
  34. filename = 'DynamicImport' + index;
  35. }
  36. import('./' + filename).then(module => {
  37. module.default.helloworld();
  38. module.default['helloworld']();
  39. });
  40. },
  41. },
  42. };
  43. </script>
  44. <style>
  45. </style>