当前位置: 首页 > Web前端 > vue.js

Vue2+Vuecli+component

时间:2023-03-31 18:43:20 vue.js

工作中遇到一个问题,需要对接口返回的数据进行处理。接口返回:你好你好,你真正需要的是:你好你好,想了想,想出了一个办法,借助组件(包括占位图片、计算最佳显示比例、预览功能等),将img替换为自己打包的ImgMsg组件。功能)。具体实现需要以下步骤:1.配置项//vue.config.jsmodule.exports={.../*是否使用包含运行时编译器的Vue构建版本。一旦设置为true,您就可以在Vue组件中使用模板选项,但这会给您的应用程序增加大约10kb。(默认false)*/runtimeCompiler:true,}2.全局注册//components/Common/index.jsimportVuefrom'vue'imoortImgMsgfrom'@/components/ImgMsg'constcomponents=[ImgMsg];components.forEach(component=>{Vue.component(component.name,component);});3.组件中使用附件:ImgMsg组件代码