当前位置: 首页 > news >正文

网站后台信息管理怎么做免费入驻的卖货平台有哪些

网站后台信息管理怎么做,免费入驻的卖货平台有哪些,微网站平台建设方案,兰州建设一个网站多少钱在 Vue.js 3 中,使用 vue3-sfc-loader 可以动态加载异步的 Vue 单文件组件(.vue 文件)。这个工具允许你在运行时根据需要加载和解析 .vue 文件,使得组件的加载变得更加灵活和动态。 下面是一个简单的示例,演示如何使用…

在 Vue.js 3 中,使用 vue3-sfc-loader 可以动态加载异步的 Vue 单文件组件(.vue 文件)。这个工具允许你在运行时根据需要加载和解析 .vue 文件,使得组件的加载变得更加灵活和动态。

下面是一个简单的示例,演示如何使用 vue3-sfc-loader 动态加载一个异步的 Vue 组件:

安装依赖: 首先,需要安装 vue3-sfc-loader@vue/compiler-sfc(Vue 3 的单文件组件编译器)。

import { loadModule } from "vue3-sfc-loader";

开始加载时需要知道的事

defineAsyncComponent 是 Vue 3 提供的用于定义异步组件的函数

<template><div><component :is="previewComp"></component></div>
</template>
  • <component :is="previewComp"></component> 是动态组件,根据 previewComp 的值来决定显示哪个组件。

 

import {ref,defineAsyncComponent,shallowRef,watch,onMounted,nextTick,
} from "vue";
import * as Vue from "vue";
import * as Cesium from "cesium";
import { loadModule } from "vue3-sfc-loader";
//映入你需要渲染的资源。包含js 在下面的代码中需要再次注册,

比如我们的vue下面仍然需要注册,第三方资源包也是如此

const init = (code: string) => {try {const options = {moduleCache: {vue: Vue,cesium: Cesium,},async getFile() {return code;},addStyle(textContent) {const style = Object.assign(document.createElement("style"), {textContent,});const ref = document.head.getElementsByTagName("style")[0] || null;document.head.insertBefore(style, ref);},};const comp = defineAsyncComponent(() =>loadModule("myComponent.vue", options));previewComp.value = comp;} catch (err) {console.error(err);}
};
  • init 方法是初始化方法,根据传入的 code 加载模块并设置到 previewComp
  • moduleCache:这是一个对象,用来缓存模块。根据代码中的变量命名,它可能预先加载了一些模块,例如 VueFFCesiumCesiumturfCesiumNavigation。这些模块可以在加载 myComponent.vue 组件时使用。

  • etFile() 函数:这是一个异步函数,返回值是传入的 code 参数,即函数初始化时传入的字符串。

  • defineAsyncComponent() 是一个 Vue 3 提供的函数,用于定义异步组件。它接受一个函数作为参数,这个函数返回一个 Promise,用来加载和解析组件。
  • loadModule("myComponent.vue", options) 调用 loadModule 函数加载名为 myComponent.vue 的 Vue 组件,并传入之前定义的 options 对象作为配置。

 就是这样拉。

然而我的示例里面previewComp是外面编辑器传进来的。展示一下源码

<template><div v-if="show" class="big"><component :is="previewComp"></component></div>
</template><script setup lang="ts">
import {ref,defineAsyncComponent,shallowRef,watch,onMounted,nextTick,
} from "vue";
import * as Vue from "vue";
import * as Cesium from "cesium";
import { loadModule } from "vue3-sfc-loader";
import * as turf from "@turf/turf";
import * as CesiumNavigation from "cesium-navigation-es6"; //指南针插件
import FFCesium from "@/FFCesium/core/index.js";let show = ref(false);
// import { particle } from "../cesium/resoure/index.ts";
const props = defineProps({code: {type: String,required: true,},
});
watch(() => props.code,(newValue, oldValue) => {// 这里可以执行其他操作console.log("监听");init(newValue);}
);onMounted(() => {// 初始化show.value = true;// 初始化init(props.code);
});
const setCode = (code: string) => {show.value = false;// 重新渲染显示页,解决改错报错不再回归console.log("yunx,shuoax");nextTick(() => {show.value = true;// 在父组件里面再调用一次init(code);});
};defineExpose({ setCode });const previewComp = shallowRef();
const init = (code: string) => {// console.log("FFCesium12", FFCesium);try {const options = {moduleCache: {vue: Vue,FFCesium: FFCesium,cesium: Cesium,turf: turf,CesiumNavigation: CesiumNavigation,},async getFile() {return code;},addStyle(textContent) {const style = Object.assign(document.createElement("style"), {textContent,});const ref = document.head.getElementsByTagName("style")[0] || null;document.head.insertBefore(style, ref);},};const comp = defineAsyncComponent(() =>loadModule("myComponent.vue", options));previewComp.value = comp;} catch (err) {console.error(err);}
};
// // 初始化
// init(props.code);
</script>
<style scoped>
.big {width: 100%;height: 100%;
}
</style>

http://www.yidumall.com/news/53768.html

相关文章:

  • 网站后台管理进入线上推广平台有哪些
  • 怎么做网站导航栏sns营销
  • 漳州网站建设哪家好百度推广投诉中心
  • 做现货黄金网站海南seo顾问服务
  • 珠海seo网站建设网站优化排名软件
  • 网站建设续费多少钱微博推广方式有哪些
  • 如何给网站做右侧导航结构优化是什么意思
  • 淘客网站怎么做海口网站关键词优化
  • 找个网站开发的师傅seo专员
  • 什么网站做家电测评百度注册入口
  • 制作网页如何设置对齐方式seo发外链工具
  • 网页设计与网站开发试题答案seo关键词优化策略
  • 怎样做禁毒网站的试卷百度百度推广
  • 网店运营推广高级实训教程seo教程网站
  • 做网站用什么编程语言搭建个人网站
  • 承德网站建设怎么做关键词排名技巧
  • 深圳市住房城乡建设委门户网站深圳网站建设公司
  • qwins是哪个网站做的百度app浏览器下载
  • 免费下载的网页模板南昌seo招聘信息
  • 网站开发需要干什么百度首页排名优化公司
  • 360平台怎么做网站优化百度推广怎么做最好
  • 网站首页 排版国外推广网站有什么
  • 网站下拉框怎么做指数分布
  • web网页是什么网站seo推广招聘
  • 广州网站建设小程序大数据营销的案例
  • 美工招聘信息西安企业seo外包服务公司
  • 做网站用什么配资电脑正规网站优化推广
  • vs2012解决方案做网站一级造价工程师
  • 网站的目录排名真难做建网站软件
  • 惠州专业网站建设价格郑州seo线上推广系统