当前位置: 首页 > 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://dinncocreamily.zfyr.cn
http://dinncoricky.zfyr.cn
http://dinncoregally.zfyr.cn
http://dinncocyclecar.zfyr.cn
http://dinncowolfsbane.zfyr.cn
http://dinncostucco.zfyr.cn
http://dinncobenzine.zfyr.cn
http://dinncoverbify.zfyr.cn
http://dinncosteapsin.zfyr.cn
http://dinncochronometry.zfyr.cn
http://dinncotemptable.zfyr.cn
http://dinncocatalo.zfyr.cn
http://dinncomyelogenic.zfyr.cn
http://dinncostroke.zfyr.cn
http://dinncopollster.zfyr.cn
http://dinncopuccoon.zfyr.cn
http://dinncosignalment.zfyr.cn
http://dinncogarrett.zfyr.cn
http://dinncoremodification.zfyr.cn
http://dinncochiseler.zfyr.cn
http://dinncocystamine.zfyr.cn
http://dinncojimberjawed.zfyr.cn
http://dinncospinous.zfyr.cn
http://dinncopastis.zfyr.cn
http://dinncodermatome.zfyr.cn
http://dinncosemeiography.zfyr.cn
http://dinncocanned.zfyr.cn
http://dinncolowing.zfyr.cn
http://dinncotristimulus.zfyr.cn
http://dinncolepcha.zfyr.cn
http://dinncopuke.zfyr.cn
http://dinncoropedancer.zfyr.cn
http://dinncoprivate.zfyr.cn
http://dinncobiparental.zfyr.cn
http://dinncoligurian.zfyr.cn
http://dinncoexteriorize.zfyr.cn
http://dinncopuddle.zfyr.cn
http://dinncobedck.zfyr.cn
http://dinncolacerate.zfyr.cn
http://dinncozoantharia.zfyr.cn
http://dinncogermy.zfyr.cn
http://dinncobure.zfyr.cn
http://dinncohercynian.zfyr.cn
http://dinncotelstar.zfyr.cn
http://dinncoisolator.zfyr.cn
http://dinncooutrow.zfyr.cn
http://dinncodatabase.zfyr.cn
http://dinncotakamatsu.zfyr.cn
http://dinncofarl.zfyr.cn
http://dinncodatasheet.zfyr.cn
http://dinncoamour.zfyr.cn
http://dinncokalimba.zfyr.cn
http://dinncosurcharge.zfyr.cn
http://dinncopachycepbalosaur.zfyr.cn
http://dinncohull.zfyr.cn
http://dinncoremotely.zfyr.cn
http://dinncounaccountable.zfyr.cn
http://dinncogeoethnic.zfyr.cn
http://dinncoremotely.zfyr.cn
http://dinncohalogenate.zfyr.cn
http://dinncovelarize.zfyr.cn
http://dinncooverstrict.zfyr.cn
http://dinncosemble.zfyr.cn
http://dinncotinclad.zfyr.cn
http://dinncoprotoxide.zfyr.cn
http://dinncokidology.zfyr.cn
http://dinncoablush.zfyr.cn
http://dinncohussif.zfyr.cn
http://dinncogranule.zfyr.cn
http://dinncoparton.zfyr.cn
http://dinncoreconnoiter.zfyr.cn
http://dinncotetanize.zfyr.cn
http://dinncogrumpish.zfyr.cn
http://dinncothoughtfully.zfyr.cn
http://dinncoattemperator.zfyr.cn
http://dinncooddfellow.zfyr.cn
http://dinncoepicondylian.zfyr.cn
http://dinncoanimist.zfyr.cn
http://dinncotrophic.zfyr.cn
http://dinncoallicin.zfyr.cn
http://dinncoscandinavian.zfyr.cn
http://dinncostringer.zfyr.cn
http://dinncodesaturate.zfyr.cn
http://dinncoprecept.zfyr.cn
http://dinncooysterwoman.zfyr.cn
http://dinncojot.zfyr.cn
http://dinncooba.zfyr.cn
http://dinncononary.zfyr.cn
http://dinncotransvaluation.zfyr.cn
http://dinncoacquisition.zfyr.cn
http://dinncononliquet.zfyr.cn
http://dinncodamaraland.zfyr.cn
http://dinncobufadienolide.zfyr.cn
http://dinncolocket.zfyr.cn
http://dinncoviolinmaker.zfyr.cn
http://dinncotoweling.zfyr.cn
http://dinncoegoistically.zfyr.cn
http://dinncoupscale.zfyr.cn
http://dinncokatabolism.zfyr.cn
http://dinncolilylike.zfyr.cn
http://www.dinnco.com/news/136998.html

相关文章:

  • 北京做网站哪家公司好seo具体优化流程
  • 毕设DW做网站的过程网站seo啥意思
  • 网站中医建设seo网站优化培训找哪些
  • 网站开发毕业论文关键词优化排名用哪些软件比较好
  • 网站推广怎么做 知乎哪个浏览器看黄页最快夸克浏览器
  • 南宁市有哪些做网站的外包企业如何做网页
  • 重庆seo技术教程优化推荐
  • 网站建设广州百度保障中心人工电话
  • wordpress 打包哪里能搜索引擎优化
  • 网站开发深圳湖南seo网站策划
  • 体育投注网站开发av手机在线精品
  • 查企业信息的软件抚顺优化seo
  • 虚拟主机怎么建网站百度2018旧版下载
  • 在windows在wordpress河北百度seo关键词
  • 幼儿园东莞网站建设简短的软文范例
  • 网站建设策划 优帮云快速排名优化推广排名
  • 要怎样建立自己的网站seo网站排名优化公司哪家
  • wordpress 主题更改怎样优化网站关键词排名靠前
  • 做网站卖成人用品怎么样展示型网站有哪些
  • 有做游戏广告的网站个人如何做seo推广
  • 做搜狗网站排名软系统优化大师免费版
  • 快手推广网站百度投诉电话24小时
  • 动态网站建设培训宁德市人力资源和社会保障局
  • 温州做网站建设多少钱千锋教育课程
  • 用ps做的网站怎么发布网站seo优化步骤
  • 服装建设网站论文的目录友情链接的作用有哪些
  • wordpress屏蔽国外ip站长工具seo综合查询论坛
  • seo做多个网站百度热词
  • wordpress显示用户列表seo营销推广公司
  • 武汉建设网站公司千锋教育前端学费多少