index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. console.log("hello world");
  2. /**
  3. console.log(process.argv);
  4. process.argv.forEach(item => {
  5. console.log(item);
  6. });
  7. console.log("dirname : "+__dirname);
  8. console.log("filename : "+__filename);
  9. **/
  10. console.log("----------------------------");
  11. const comm=require("./commonjs.js");
  12. comm.info();
  13. console.log("----------------------------");
  14. //import {esname,esfunc} from "./es.mjs"
  15. //es.func();
  16. console.log("----------------------------");
  17. console.log("<h3>this is node test string!!!</h3>");
  18. //const {createApp}=Vue;
  19. import {createApp } from 'vue';
  20. //import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js';
  21. //import { createApp } from './js/vue.esm-browser.js';
  22. //import { createApp } from './js/vue.global.js';
  23. //import { Home } from "./vue/Home.vue";
  24. import Home from "./vue/Home.vue";
  25. import test from "./vue/test.vue";
  26. import About from "./vue/About.vue";
  27. import i18n from "./i18n.js";
  28. import { useI18n } from 'vue-i18n';
  29. /**
  30. const { locale,t } = useI18n();
  31. console.log("----------------------------");
  32. const changelang = type => {
  33. console.log(locale);
  34. console.log("----------------------------");
  35. locale.value=type;
  36. }
  37. **/
  38. //import router from "./router.vue";
  39. import router from "./router.js";
  40. import ElementPlus from 'element-plus'
  41. import 'element-plus/dist/index.css'
  42. //console.log(createApp);
  43. //console.log(i18n);
  44. console.log(router);
  45. const app=createApp({
  46. template:'#my-app',
  47. // template:`<div v-html='info'>template</div>`,
  48. components:{
  49. Home,
  50. test,
  51. About
  52. },
  53. data(){
  54. return{
  55. info:`<span style='color:red; font-size:30px'>hello vue template</span>`,
  56. number:0,
  57. locale:null,
  58. options:[
  59. {value: 'zh', label: '中文',},
  60. {value: 'en', label: 'English',},
  61. {value: 'ja', label: 'にほんご',},
  62. ],
  63. tomcat_res:"tomcat",
  64. books:[
  65. {title:"Linux从入门到精通",author:"night-cherry",publisher:"peking press",pages:123},
  66. {title:"MySQL必知必会",author:"李晓兵",publisher:"peking press",pages:456},
  67. ],
  68. }
  69. },
  70. methods:{
  71. add(){
  72. this.number++;
  73. },
  74. changelang(type){
  75. console.log("-----------change lang-----------------");
  76. console.log("this.locale : "+this.locale);
  77. console.log("locale"+locale);
  78. this.locale=locale;
  79. console.log("this.locale : "+this.locale);
  80. locale.value=type;
  81. },
  82. interface_web(){
  83. console.log("---------tomcat server----------");
  84. console.log("this.tomcat_res : "+this.tomcat_res);
  85. console.log("------this.books : "+this.books);
  86. const _books=this.books;
  87. let _tomcat_res=this.tomcat_res;
  88. // console.log("------this : "+this);
  89. const request = new XMLHttpRequest();
  90. request.onload=function(){
  91. console.log("--------parse tomcat server string--------");
  92. const res=JSON.parse(request.responseText);
  93. _tomcat_res=res[0].title;
  94. console.log("res:"+res);
  95. console.log("res[0].title :"+res[0].title);
  96. console.log("res[0].author :"+res[0].author);
  97. console.log("res[0].publisher :"+res[0].publisher);
  98. console.log("res[0].pages :"+res[0].pages);
  99. console.log("res[1]:"+res[1]);
  100. console.log("res[1][\"title\"] :"+res[1]["title"]);
  101. console.log("res[1][\"author\"] :"+res[1]["author"]);
  102. console.log("res[1].publisher :"+res[1].publisher);
  103. console.log("res[1].pages :"+res[1].pages);
  104. console.log("this.tomcat_res : "+this.tomcat_res);
  105. alert("this.tomcat_res : "+_tomcat_res);
  106. console.log("------ _books : "+_books);
  107. // console.log("------this.books : "+this.books);
  108. try{
  109. for(const item of res){
  110. console.log(item);
  111. _books.push(item);
  112. }
  113. // _books.concat(res);
  114. }catch(e){
  115. console.log("the way == _books.push(res[0]) is wrong!!!");
  116. try{
  117. _books.push(res[0]);
  118. }catch(e){
  119. console.log("the way == _books.push(res[0]) is wrong!!!");
  120. }
  121. }finally{
  122. console.log("--object array operation done--");
  123. }
  124. // console.log("------books : "+books);
  125. // console.log("------this : "+this);
  126. console.log("this.tomcat_res : "+_tomcat_res);
  127. };
  128. request.open("POST","http://ancientapes.cc:8080/mineluxuries/book");
  129. request.send("test tomcat");
  130. }
  131. },
  132. setup(){
  133. const { locale,t } = useI18n();
  134. console.log("-------get locale--------");
  135. console.log("locale : "+locale);
  136. // this.locale=locale;
  137. // 在根文件直接使用locale需要绑定一个locale变量至浏览器对象Window
  138. // 否则无法让methods中的方法调用其中的变量(全局变量)
  139. // 如果封装在组件中,然后提供给父组件使用,则直接定义函数即可
  140. window.locale=locale;
  141. // this.locale=locale;
  142. // console.log("this.local : "+this.locale);
  143. console.log("-------after get locale--------");
  144. }
  145. }).use(i18n).use(router).use(ElementPlus).mount("#app");
  146. //Vue.createApp(app).mount("#app");
  147. console.log("end the vue template render");