vue3 异步组件例子

vueloader use js

目前为 2022-06-28 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/447165/1065325/vue3%20%E5%BC%82%E6%AD%A5%E7%BB%84%E4%BB%B6%E4%BE%8B%E5%AD%90.js

  1. // ==UserScript==
  2. // @name vue3 异步组件例子
  3. // @namespace moe.canfire.flf
  4. // @description vueloader use js
  5. // @author mengzonefire
  6. // @license MIT
  7. // @match *
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @grant GM_deleteValue
  11. // @grant GM_setClipboard
  12. // @grant GM_xmlhttpRequest
  13. // @grant GM_info
  14. // @grant GM_getResourceText
  15. // @grant GM_addStyle
  16. // @grant unsafeWindow
  17. // @run-at document-start
  18. // @connect *
  19. // @version 0.0.1.20220314074202
  20. // ==/UserScript==
  21.  
  22. async function myimport(jsurl,enableCache){
  23. if(!enableCache) jsurl=jsurl +'?rnd='+Math.random();
  24. let data = await fetch(jsurl).then(res=>res.text() );
  25. try{
  26. data=data.substr(data.indexOf('{')+0).trim();//
  27. var json=(new Function("return " + data ))();
  28. //自动插入css
  29. if( json.css!=undefined ){
  30. var style = document.createElement('style');
  31. var head = document.head || document.getElementsByTagName('head')[0];
  32. style.innerHTML=style.innerHTML+json.css;
  33. head.appendChild(style);
  34. }///
  35. return json;
  36. }catch (error) {
  37. console.log( jsurl );
  38. console.log( error.name+ error.message );
  39. }
  40. };//---------------------------
  41.  
  42. const app = Vue.createApp({
  43. data:function(){return {
  44. }},//data-----
  45. methods: {
  46. },//methods-----
  47. components: {
  48. test:Vue.defineAsyncComponent(() => myimport("./test.js",false) )
  49. }
  50. });
  51. app.use(vant);
  52. app.use(vant.Lazyload);
  53. const vm=app.mount('#app');
  54. //////////////////////////////////////
  55. // test.js //export
  56. const test = {
  57. template: `
  58. 这是 <span class=mycss>组件测试</span>
  59. 参数:{{str1}}<br>
  60. `,
  61. model: {
  62. prop: ['str']
  63. },
  64. props: {
  65. str: String
  66. },
  67. css:` .mycss{ border:5px solid red;} `
  68. ,
  69. setup(props) {
  70. // 在setup里面获取参数值
  71. const str1 = Vue.ref(props.str)
  72. return {
  73. str1
  74. }
  75. },
  76. };
  77.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址