Front-end component sharing method, device, electronic device and readable storage medium

The shared components are transcoded and packaged through a transcoder, and the decoder is used to dynamically decode references during the front-end rendering process, which solves the problems of high coupling and complex steps in the front-end component sharing process, and improves sharing efficiency and simplicity.

CN118568376BActive Publication Date: 2024-10-18CIVIL AVIATION CHENGDU INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411046776.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-01
Publication Date
2024-10-18
Estimated Expiration
2044-08-01

AI Technical Summary

Technical Problem

In the existing technology, the sharing process of front-end components is highly coupled, resulting in cumbersome and complicated component reference steps and low sharing efficiency. Especially when the source code of the referenced project or the packaged js file needs to be updated, the referenced project must also be updated. Making corresponding updates makes the shared component reference steps cumbersome and complicated.

Method used

By introducing a transcoder to transcode and package shared components, and using the decoder to dynamically access the transcoded shared component compressed files during the front-end rendering process, directly decode and reference the shared component compressed files, reducing the degree of coupling between projects and simplifying Reference steps.

Benefits of technology

It improves the simplicity and efficiency of component sharing, reduces the reference steps, and reduces the coupling between projects, making component sharing more efficient and simpler.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118568376B_ABST
    Figure CN118568376B_ABST
Patent Text Reader

Abstract

The present invention provides a front-end component sharing method, device, electronic device and readable storage medium, which are applied to the field of big data technology. When there is a need for a shared component during the front-end rendering process, a decoder is introduced and loaded; after controlling the decoder to dynamically decode the shared component compressed file, the decoded shared component is loaded; the shared component compressed file is obtained by accessing the URL where the transcoded file is stored; the shared component compressed file is generated by transcoding the shared component through a transcoder; based on the component information of the decoded shared component, the decoded target shared component is rendered. In this way, during the front-end rendering process, the shared component compressed file is directly decoded and referenced, which reduces the coupling degree between projects when the shared component is cross-referenced, reduces the reference steps, and improves the simplicity and efficiency of component sharing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of big data technology, and in particular to a method, device, electronic device and readable storage medium for sharing front-end components. Background Art

[0002] Front-end development is the process of creating front-end interfaces such as WEB pages or APPs to present to users. It uses HTML, CSS, JavaScript, and various derived technologies, frameworks, and solutions to achieve user interface interaction of Internet products. In the process of front-end development, Vue.js has become one of the current mainstream front-end frameworks. However, there is a need for cross-reference of data between some systems during operation and cross-reference of *.vue components generated during the development process. Therefore, each project has the need for shared components. Therefore, when it is determined that there is a need for shared components, it is necessary to call the project of the shared components and call the shared components in the referenced project.

[0003] In the related art, generally, when packaging a referenced project, the source code of the shared component of the referenced project or the generated packaged js file needs to be packaged into the source code of the referenced project at the same time. There is a high coupling between the referenced project and the referenced project. If the source code or logic of a shared component of the referenced project is modified later, the referenced project must also update related dependencies and release projects to complete the complete update of the shared component, which makes the steps of referencing shared components cumbersome and complicated, resulting in cumbersome and complicated component sharing and low sharing efficiency. Summary of the invention

[0004] In view of this, the purpose of the present invention is to provide a front-end component sharing method, device, electronic device and readable storage medium, the shared components are transcoded and packaged by a transcoder, and during the front-end rendering process, the transcoded shared component compressed file is dynamically accessed by a decoder, and the shared component compressed file is directly decoded and referenced, thereby reducing the degree of coupling between projects when the shared components are cross-referenced, reducing the reference steps, and helping to improve the simplicity and efficiency of component sharing.

[0005] In a first aspect, an embodiment of the present invention provides a method for sharing a front-end component, the method comprising:

[0006] When there is a need for shared components during the front-end rendering process, the decoder is introduced and loaded;

[0007] After controlling the decoder to dynamically decode the shared component compressed file, the decoded shared component is loaded; wherein the shared component compressed file is obtained by accessing the URL where the transcoded file is stored; the shared component compressed file is generated by transcoding the shared component by the transcoder;

[0008] Based on the component information of the decoded shared component, the decoded target shared component is rendered.

[0009] In a possible implementation manner, the decoder dynamically decodes the shared component compressed file in a manner including an automatic decoding manner and a manual decoding manner;

[0010] When the method in which the decoder dynamically decodes the shared component compressed file includes an automatic decoding method, the method of controlling the decoder to dynamically decode the shared component compressed file and then loading the decoded shared component includes:

[0011] When it is detected that the property of the global component created after the introduction of the decoder has changed, automatically determining whether the global variable created after the introduction of the decoder exists;

[0012] If it exists, check whether there is a shared component that has been loaded historically;

[0013] If there is a shared component that has been loaded in the past, the shared component that has been loaded in the past is uninstalled, and the decoder is controlled to dynamically decode the shared component compressed file, and then the decoded shared component is loaded.

[0014] In a possible implementation, after detecting whether there is a shared component that has been loaded historically, the sharing method further includes:

[0015] If there is no shared component that has been loaded historically, the decoder is controlled by the manual decoding method to dynamically decode and load the shared component compressed file.

[0016] In a possible implementation manner, controlling the decoder to dynamically decode and load the shared component compressed file through the manual decoding method includes:

[0017] Call the first target function to pass in the name of the decoded shared component to be loaded, the callback function and the loading parameters;

[0018] Detect whether the shared component after being passed in has a component name or whether the loading parameter is a valid parameter object;

[0019] If the shared component has a component name and the loading parameter is a valid parameter object, define a temporary string, and determine that the temporary string contains file name information;

[0020] After building and loading the shared file based on the temporary string, register the global component;

[0021] After the global component registration is completed, if it is determined according to the callback function that there is no other callback function, the loading process is terminated.

[0022] In a possible implementation, the global component is registered by following the steps below:

[0023] Check whether the global components to be registered contain the information of the components to be registered;

[0024] If the global component to be registered does not contain the component information to be registered, calling the second target function to register the component information to be registered into the global component in the instance;

[0025] Based on the name information in the component information to be registered, detecting whether there is a shared component and shared component information in the decoder;

[0026] If there are shared components and shared component information in the decoder, completing the registration of the global component based on the shared component information;

[0027] If the shared component and the shared component information do not exist in the decoder, the registration of the global component is completed based on the registration information indicated by the created temporary variable.

[0028] In a possible implementation manner, the sharing method further includes:

[0029] Uninstalls the shared components registered by the decoder.

[0030] In a possible implementation, the transcoder is controlled to transcode the shared component to generate the shared component compressed file through the following steps:

[0031] Introducing the transcoder and creating a temporary folder; wherein the temporary folder is used to store temporary files generated during the transcoding process;

[0032] Creating a corresponding temporary file for at least one shared component to be transcoded; the temporary file is used to import the corresponding shared component;

[0033] Transcoding the generated at least one temporary file using a front-end packaging tool to obtain at least one initial transcoded shared component file;

[0034] After each initially transcoded shared component file is adjusted to an accessible shared component file, the shared component compressed file is generated.

[0035] In a second aspect, an embodiment of the present invention further provides a sharing device of a front-end component, the sharing device comprising:

[0036] The decoder import module is used to import and load the decoder when there is a need for shared components during the front-end rendering process;

[0037] A component loading module, used to control the decoder to dynamically decode the shared component compressed file and then load the decoded shared component; wherein the shared component compressed file is obtained by accessing the URL where the transcoded file is stored; the shared component compressed file is generated by transcoding the shared component by the transcoder;

[0038] The component rendering module is used to render the decoded target shared component based on the component information of the decoded shared component.

[0039] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium through the bus, and the processor executes the machine-readable instructions to perform the front-end component sharing method as described in any one of the first aspects.

[0040] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the front-end component sharing method as described in any one of the first aspects is executed.

[0041] The front-end component sharing method, device, electronic device and readable storage medium provided by the embodiment of the present invention introduce and load a decoder when there is a need for a shared component during the front-end rendering process; control the decoder to dynamically decode the shared component compressed file, and then load the decoded shared component; wherein the shared component compressed file is obtained by accessing the URL where the transcoded file is stored; the shared component compressed file is generated by transcoding the shared component through a transcoder; and based on the component information of the decoded shared component, the decoded target shared component is rendered. In this way, the shared component is transcoded and packaged by the transcoder, and during the front-end rendering process, the transcoded shared component compressed file is dynamically accessed by the decoder, and the shared component compressed file is directly decoded and referenced, thereby reducing the degree of coupling between projects when the shared components are cross-referenced, reducing the reference steps, and helping to improve the simplicity and efficiency of component sharing.

[0042] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.

[0044] Figure 1 A flow chart of a front-end component sharing method provided by an embodiment of the present invention;

[0045] Figure 2 One of the structural schematic diagrams of a front-end component sharing device provided by an embodiment of the present invention;

[0046] Figure 3 A second structural diagram of a front-end component sharing device provided by an embodiment of the present invention;

[0047] Figure 4 The present invention is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0048] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. The components of the embodiments of the present invention generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, each other embodiment obtained by those skilled in the art without making creative work belongs to the scope of protection of the present invention.

[0049] First, the application scenarios to which the present invention is applicable are introduced. The present invention can be applied to the field of big data technology.

[0050] Front-end development is the process of creating front-end interfaces such as WEB pages or APPs to present to users. It uses HTML, CSS, JavaScript, and various derived technologies, frameworks, and solutions to achieve user interface interaction of Internet products. In the process of front-end development, Vue.js has become one of the current mainstream front-end frameworks. However, there is a need for cross-reference of data between some systems during operation and cross-reference of *.vue components generated during the development process. Therefore, each project has the need for shared components. Therefore, when it is determined that there is a need for shared components, it is necessary to call the project of the shared components and call the shared components in the referenced project.

[0051] Cross-reference of data, whether in development nodes or during operation, can be solved by using existing technologies such as window variables, browser cache, or micro-frontend technology (such as qiankun), but it requires high technical requirements and is difficult for R&D personnel to use.

[0052] In a possible implementation, the cross-references of components can be introduced in different ways during the development phase, and then referenced in a static form in the referencing project.

[0053] Specifically, the introduction methods of cross-references of components in the development stage include: Method 1: strong introduction through relative paths such as ". / ** / *.vue" in the referencing project; Method 2: soft link (npm link) of the referenced project; Method 3: copy the shared *.vue component files and their dependent files of the referenced project to the referencing project; Method 4: separately package the *.vue components to be shared into js files (if the vue component references a dependent package such as element, it is required to package the source code of the dependent package into js at the same time, and the packaged js is generally very large).

[0054] In the above-mentioned related technologies, generally, when packaging the referenced project, the source code of the shared component of the referenced project or the generated packaged js file needs to be packaged into the source code of the referenced project at the same time. There is a high coupling between the referenced project and the referenced project. If the source code or logic of a shared component of the referenced project is modified later, the referenced project must also update the relevant dependencies and release projects to complete the complete update of the shared component, which makes the steps of referencing the shared component cumbersome and complicated, resulting in cumbersome and complicated component sharing and low sharing efficiency.

[0055] Based on this, an embodiment of the present invention provides a method for sharing front-end components to reduce the degree of coupling between projects when shared components are cross-referenced, reduce the reference steps, and improve the simplicity and efficiency of component sharing.

[0056] See also Figure 1 , Figure 1 The following is a flow chart of a method for sharing front-end components provided by an embodiment of the present invention. Figure 1 As shown in , the front-end component sharing method provided by the embodiment of the present invention includes:

[0057] S101. When there is a need for shared components during the front-end rendering process, a decoder is introduced and loaded.

[0058] S102, controlling the decoder to dynamically decode the shared component compressed file, and then loading the decoded shared component; wherein the shared component compressed file is obtained by accessing the URL where the transcoded file is stored; and the shared component compressed file is generated by transcoding the shared component by the transcoder.

[0059] S103: Render the decoded target shared component based on the component information of the decoded shared component.

[0060] The front-end component sharing method provided in the embodiment of the present invention transcodes and packages the shared components through a transcoder. During the front-end rendering process, the transcoded shared component compressed file is dynamically accessed through a decoder, and the shared component compressed file is directly decoded and referenced, thereby reducing the degree of coupling between projects when the shared components are cross-referenced, reducing the reference steps, and helping to improve the simplicity and efficiency of component sharing.

[0061] The following is a description of the exemplary steps of the embodiment of the present invention:

[0062] S101. When there is a need for shared components during the front-end rendering process, a decoder is introduced and loaded.

[0063] In an embodiment of the present invention, front-end development is the process of creating a front-end interface such as a WEB page or an APP to present it to the user. The user interface interaction of Internet products is realized through HTML, CSS and JavaScript and various technologies, frameworks and solutions derived therefrom. In the process of front-end development, Vue.js has become one of the current mainstream front-end frameworks. However, there is a need for cross-reference of data between some systems and cross-reference of *.vue components generated during the development process. Therefore, each project (which can be a project in the development process or a project in the running state) has a need for shared components. Therefore, when it is determined that there is a need for shared components, it is necessary to call the project of the shared components and call the shared components in the referenced project.

[0064] In a possible implementation, the transcoded shared component may be accessed and loaded by loading a decoder.

[0065] The reference to the decoder may be a global reference or a local reference.

[0066] Specifically, the decoder js can be introduced and stored in a temporary variable VueDecoder. Specifically, the method of introducing the decoder (js language) can be: import VueDecoder from 'vue-decoder'.

[0067] Furthermore, after the decoder is introduced, it is necessary to load the decoder in the project (the current vue instance), and after loading the decoder, a global variable $decoder and a global component vue-decoder will be created on the current vue instance for subsequent processing. At the same time, there is an internal variable components on the global variable $decoder to store information related to components that have been decoded and registered by the decoder.

[0068] In a possible implementation manner, the method of recording the decoder (js language) may include any of the following methods:

[0069] Loading method 1: app.use (VueDecoder, options);

[0070] Loading method 2: ueDecoder.install(app,options);

[0071] Loading method 3: new VueDecoder .Decoder(options).

[0072] Among them, the app in the parameter refers to the current vue instance that currently loads the decoder, globalKey: no need to fill in, the default is $decoder, which is the new global variable name after loading; baseUrl: no need to fill in, the url request prefix that can be abbreviated when *.umd.js is dynamically loaded later; suffix: no need to fill in, the url request suffix that can be abbreviated when *.umd.js is dynamically loaded later; mode: no need to fill in, the default quote, component creation mode, used for user configuration if the component to be dynamically introduced already has a component of the same name on the global instance of the introduced project, the decoder handles the dynamically introduced component in the following ways: add (forced reconstruction, overwriting the original component), quote (no reconstruction, directly quote the existing component), rename (rename and create a new component).

[0073] Further, after determining that the current Vue instance has introduced and loaded the decoder, the process of introducing, decoding, registering, etc. of the obtained shared component compressed file can be controlled by the decoder, so that the current Vue instance can reference the shared components that need to be referenced.

[0074] In a possible implementation manner, the ways for the decoder to dynamically decode the shared component compressed file include an automatic decoding method and a manual decoding method. There are certain differences in the operation of different decoding methods. The different decoding methods will be elaborated below.

[0075] First, when the way for the decoder to dynamically decode the shared component compressed file includes the automatic decoding method:

[0076] The step of "controlling the decoder to dynamically decode the shared component compressed file and then load the decoded shared component" includes:

[0077] a1: When the attributes of the global component created after detecting the introduction of the decoder change, automatically determine whether the global variable created after the introduction of the decoder exists.

[0078] a2: If it exists, detect whether there is a shared component that has been loaded historically.

[0079] a3: If there is a shared component that has been loaded historically, unload the shared component that has been loaded historically, and then control the decoder to dynamically decode the shared component compressed file and load the decoded shared component.

[0080] In the embodiment of the present invention, after determining the introduction and loading of the decoder, the global component vue-decoder has been created. When decoding, the global component [vue-decoder] provided by the decoder can be directly used to assign a value to the url attribute to use the component and render the shared component.

[0081] Specifically, the path of the shared component *.umd.js to be used is specified through the url attribute (example: <vue-decoder url="*.umd.js address" / >). This component defines the attribute variable url (the attribute variable is the props attribute) and the data variable componentName (the data variable is the data attribute) used in the component to record the name of the component that was successfully loaded automatically last time.

[0082] In a possible implementation, the specific working principle of the global component vue-decoder is as follows: monitor whether the properties of the global component vue-decoder have changed, where the properties of vue-decoder can be url properties; if it is determined that the properties of the global component vue-decoder have changed, automatically trigger the reload function defined in the component to reload the component.

[0083] Furthermore, the function reload of the reloading component detects whether the global variable $decoder created after the decoder is introduced exists. If the detection result indicates that the global variable $decoder does not exist, it is determined that the loading of the decoder has failed. At this time, it is necessary to prompt that the loading of the decoder has failed and the decoder needs to be reloaded. If the test result indicates that the global variable $decoder does not exist, it is determined that the loading of the decoder is successful. At this time, it is necessary to detect the information of the historical loading of shared components again to detect whether there is a shared component that has been loaded. If there is a shared component that has been loaded in the past, it is necessary to uninstall the historically loaded component before loading and decoding the current shared component.

[0084] Specifically, the method for determining whether there is a shared component that has been loaded historically can be: determine whether the value of the variable componentName of the shared component that was loaded last time is empty: if it is not empty (there is a shared component that has been loaded historically), call the $decoder.uninstall function and pass in the variable componentName of the component name to be uninstalled to uninstall the shared component that was automatically loaded last time.

[0085] In a second aspect, when the decoder dynamically decodes the shared component compressed file in a manual decoding manner:

[0086] Furthermore, after the step of “detecting whether there is a shared component that has been historically loaded”, the sharing method further includes:

[0087] b1: If there is no shared component that has been loaded historically, the decoder is controlled by the manual decoding method to dynamically decode and load the shared component compressed file.

[0088] In a possible implementation, if it is determined that there is no shared component that has been loaded in the past, it is necessary to control the decoder to decode and load the shared component compressed file through manual decoding.

[0089] For the above example, determine whether the value of the shared component variable componentName loaded last time is empty. If it is empty, it is necessary to control the decoder to decode and load the shared component compressed file through manual decoding.

[0090] Specifically, the step of "controlling the decoder to dynamically decode and load the shared component compressed file through the manual decoding method" includes:

[0091] c1: Call the first target function to pass in the name of the shared component to be loaded after decoding, the callback function, and the loading parameters.

[0092] c2: Check whether the shared component has a component name or whether the loading parameter is a valid parameter object.

[0093] c3: If the shared component has a component name and the loading parameter is a valid parameter object, define a temporary string and determine that the temporary string contains file name information.

[0094] c4: After building and loading the shared file based on the temporary string, register the global component.

[0095] c5: After the global component registration is completed, if it is determined according to the callback function that there is no other callback function, the loading process is ended.

[0096] In an embodiment of the present invention, the first target function may be $decoder.intsall, according to which the name of the decoded shared component ($decoder.intsall function parameter: componentName), the callback function ($decoder.intsall function parameter: callback) and the loading parameters ($decoder.intsall function parameter: options) are passed into the $decoder.intsall function.

[0097] Among them, componentName: required, represents the full address url of the HTTP server where the shared component *.umd.js to be loaded is located, or a concise string after omitting the baseUrl prefix and suffix suffix configured in step 2; callback: optional, the function that will be triggered after the component is loaded; options: optional, represents the personalized configuration to be used during this loading (some default values ​​configured in advance for each component to be loaded). If some attributes of the options parameter are not passed in, they will be filled with the attribute values ​​of the configured global options parameter to ensure that the options value used later is a complete and valid object.

[0098] In a possible implementation, for each loading process, each loading process or loading target object may be different to a certain extent, and it is necessary to set the options parameter to represent the personalized parameters of this loading.

[0099] Specifically, for example, after the vue shared component is installed, it is actually in the form of a key-value pair, where comonentName is the key value; one of the important parameters of the options parameter is the destination object that the shared component wants to load into. If it is not pointed out, the component cannot be loaded after loading (the destination object is to limit the meaningful spatial range of the loaded component, and the loaded component can only be used in this space).

[0100] In a possible implementation, the process of loading, decoding, and registering the passed-in parameters by the first target function ($decoder.intsall) is described as follows:

[0101] Check whether the shared component passed in has a component name or whether the loading parameter is a valid parameter object; in one possible implementation, if it is determined that the shared component has no component name or the loading parameter is an invalid parameter object, and if the current callback function does not have other callback functions (the callback function parameters are empty), it is determined that the loading process is completed.

[0102] In another possible implementation, if the shared component has a component name and the loading parameter is a valid parameter object, a temporary string is defined, and it is determined that the temporary string contains file name information, and the global component is registered. If it is determined that the global component registration is completed, and it is determined based on the callback function that there are no other callback functions, the loading process is terminated.

[0103] Exemplarily, the specific implementation of the above process may be:

[0104] Step (1): Determine whether the passed comonentName parameter is empty or whether the passed options parameter is a valid parameter object. If the comonentName parameter is empty or the options parameter is an invalid parameter object, end the loading process; if the comonentName parameter is not empty and the options parameter is a valid parameter object.

[0105] Step (2): Define a temporary string variable url, and determine whether the passed comonentName string ends with the passed options.suffix suffix attribute value: If not, assign the new string value spliced ​​according to the specified splicing rule to the temporary variable url (splicing rule: [comonentName + "." + suffix]), and then execute step (3); if yes, jump to step (4).

[0106] Step (3): Determine whether the constructed temporary variable url starts with http or https. If not, add the options.baseUrl value as a prefix to the url variable value (splicing rule: [options.baseUrl + " / " +url]), parse the valid file name from the obtained url and convert the file name to a camel case string and store it in the temporary string variable humpName, then execute step (4); if yes, directly jump to step (4).

[0107] Step (4): Use document to construct a new <script>dom元素存放于临时变量scriptDom中,构造的scriptDom元素标签对象的属性值包含url和onload:url为步骤(3)处理后得到的url变量,onload为funtion函数,追加scriptDom元素到document的头部,进入步骤(4)。

[0108] 步骤(5):加载完步骤(4)的js后,在options.app实例上进行全局组件的注册。

[0109] 步骤(6):如果回调函数callback存在则调用回调函数callback,参数为空,装载结束。

[0110] 在一种可能的实施方式中,需要对全局组件的注册方式进行阐述。

[0111] 具体地,通过以下步骤注册所述全局组件:

[0112] d1:检测待注册的全局组件中是否包含待注册组件信息。

[0113] d2:若所述待注册的全局组件中不包含待注册组件信息,调用第二目标函数将所述待注册组件信息注册到实例中的全局组件中。

[0114] d3:基于所述待注册组件信息中的名称信息,检测所述解码器中是否存在共享组件以及共享组件信息。

[0115] d4:若所述解码器中存在共享组件以及共享组件信息,基于所述共享组件信息完成所述全局组件的注册。

[0116] d5:若所述解码器中不存在共享组件以及共享组件信息,基于创建的临时变量指示的注册信息完成所述全局组件的注册。

[0117] 在本发明实施例中,检测在待注册的全局组件中是否包含待注册组件信息,若是确定待注册的全局组件中不包含待注册组件信息,调用第二目标函数将所述待注册组件信息注册到实例中的全局组件中(其中,第二目标函数可以为options.app.compoennt函数);基于待注册组件信息中的名称信息,检测解码器中是否存在共享组件以及共享组件信息;若所述解码器中存在共享组件以及共享组件信息,确定当前解码器已经装载共享组件,基于共享组件信息完成全局组件的注册;若解码器中不存在共享组件以及共享组件信息,确定当前解码器中并不存在共享组件的信息,基于创建的临时变量指示的注册信息完成全局组件的注册。

[0118] 示例性地,上述全局注册过程具体实施方式可以为:

[0119] 第一步、从浏览器变量globalThis上读取key值为与步骤(3)解析的humpName值相同的变量值(即globalThis[humpName])并将值存放于临时变量newComponent中,newComponent为即将被注册的新组件对象;

[0120] 第二步:判断newComponent是否为空且newComponent.name是否为空:如果不为空跳转到第三步;如果为空,跳转到第十步;

[0121] 第三步:创建一个临时变量count,初始值为0,然后判断该次函数中options.app实例上是否已经存在全局组件名为newComponent.name的组件,如果不存在跳转到第八步;如果存在,跳转到第四步;

[0122] 第四步:判断该次函数中options.mode的值,如果为add跳转到第五步;如果为rename跳转到第六步,如果为quote跳转到第七步;

[0123] 第五步:移除当前app实例上已经存在的全局组件newComponent.name,跳转到第八步;

[0124] 第六步:将newComponent.name值重新用新的uuid进行覆盖,将组件重命名,跳转到第八步;

[0125] 第七步:给第三步创建的count变量赋值为1,跳转到第九步;

[0126] 第八步:通过options.app.compoennt函数将newComponent组件注册到options.app实例的全局组件上;

[0127] 第九步:以newComponent.name为key值,读取在当前解码器中的对象components映射的值并存放于临时变量value,判断value的值是否为空:如果为空,则将第三步创建的临时变量count的当前值赋值给value;

[0128] 第十步:将第九步得到的value值执行自增1,然后将value存放在对象components中的键值为newComponent.name的属性中;

[0129] 第十一步:移除步骤(4)创建的scriptDom节点,移除globalThis对象上键值为humpName的属性;

[0130] 第十二步:如果回调函数callback存在则调用回调函数callback,参数为newComponent.name,如果不存在则直接结束install装载方法。

[0131] 在一种可能的实施方式中,若是确定当前对于共享组件的装载过程结束,或者是需要卸载历史被加载的共享组件时,需要将对应的在解码器中将注册的共享组件进行卸载。

[0132] 具体地,所述共享方法还包括:

[0133] e1:卸载通过所述解码器解码注册的共享组件。

[0134] 在一种可能的实施方式中,可以调用$decoder.unintsall函数并传入要卸载的组件名(参数名:componentName)、针对本次装载的个性化参数(参数名:options)。

[0135] 其中,componentName:必填,代表想要被装载的组件名,为装载时通过callback参数返回的字符串;options:可选,表示本次卸时会使用的个性配置,传入的options参数个各个属性值如果某些属性没有传入值则会用中配置的全局options参数的各个属性值填充,保证后面用到的options值是完整有效的对象。

[0136] 具体地,$decoder.unintsall方法对卸载共享组件过程如下:

[0137] 1)、判断传入的comonentName参数是否为空或传入的options参数是否为有效参数对象,如果comonentName参数为空或options参数为无效参数对象,卸载共享组件,结束装载过程;如果comonentName参数不为空且options参数为有效参数对象跳转到下一步;

[0138] 2)、读取在当前解码器中的对象components上键值为componentName属性的值并存放于临时变量value,判断value的值是否等于1:如果等于1,删除在对象components上键值为componentName的属性且移除options.app实例上已经注册的全局组件名为componentName的组件。

[0139] 值得注意的是,对于在本次装载过程中的共享组件,若是确定当前共享组件已经装载完毕,可以卸载该共享组件;也可以不进行共享组件的卸载,在下一次共享组件的装载过程中将该共享组件作为上一次加载的历史共享组件进行卸载。

[0140] 在一种可能的实施方式中,经过上述过程可以完成引用项目对被引用项目的导出的转码器转码后的共享组件(*.umd.js)进行动态引入、解码、注册的过程。其中,解码器对于共享组件的访问是通过对于通过转码器转码后的*.umd.js集合的网址进行访问,这个存储共享组件转码后的共享组件集合可以是存储在服务器上。

[0141] 在一种可能的实施方式中,对于共享组件的转码过程也是通过转码器进行处理的,下面将对转码器的具体处理过程进行阐述。

[0142] 具体地,通过以下步骤控制所述转码器对共享组件进行转码生成所述共享组件压缩文件:

[0143] f1:引入所述转码器,并创建临时文件夹;其中,所述临时文件夹用于存储转码过程中生成的临时文件。

[0144] f2:针对于待转码的至少一个共享组件创建对应的临时文件;所述临时文件用于导入对应的共享组件。

[0145] f3:通过前端打包工具对生成的至少一个临时文件进行转码处理,得到至少一个初始转码共享组件文件。

[0146] f4:将各个初始转码共享组件文件调整为可访问的共享组件文件后,生成所述共享组件压缩文件。

[0147] 在本发明实施例中,可以是利用打包工具(例如,gulp),在gulp配置文件中引入转码器插件。

[0148] 在一种可能的实施方式中,可以是在gulp配置文件中项目根目录下的gulpfile.js文件中引入转码器插件。

[0149] 其中,gulpfile.js引入转码器的内容(js语言)如下所示:

[0150] const VueEncoder = require('vue-encoder');

[0151] const encoder= new VueEncoder(options);

[0152] exports.default = encoder;

[0153] 具体地,对于上述语句中的参数说明如下:input:为必填项,指定想要共享的组件*.vue输入口路径(以下简称:输入口),路径可包含*通配符,与gulp.src的参数保持一致,如:src / shares / ** / *.vue;output:不是必填项,默认值为public / globals,通过转码器转码后输出的js文件的输出口路径(以下简称:输出口),与gulp.dest参数保持一致。

[0154] 进一步的,在通过打包工具在配置文件中引入转码器后,需要创建一个临时文件夹(例如,temp-coder-imports),通过临时文件夹存放在转码过程中的生成的临时js文件。并且,同样的,创建的临时文件夹可以是自动在项目根目录下创建的。

[0155] 在一种可能的实施方式中,构建一个转码器工具可以同时转换多个共享组件,在输入入口中输入多少个.vue文件就可以转换相应数量的共享组件。并且在输入口输入多个共享组件后,为待转码的至少一个共享组件(*.vue创)创建对应的临时文件,创建的临时文件用于导入对应的vue组件,并且创建的多个临时文件均存储在预先创建的临时文件夹temp-coder-imports中,临时文件中的信息表征共享组件的来源(文件路径)。

[0156] 其中,临时的js文件内容规则为:

[0157] import Vue组件文件名驼峰 from 'vue组件文件路径';

[0158] export default Vue组件文件名驼峰;

[0159] 进一步的,为前端打包工具生成的至少一个临时文件进行转码处理后,得到至少一个初始转码共享组件,而初始转码共享组件文件可能并不能直接被访问,需要将初始转码共享组件文件调整为可访问的共享组件文件后,生成共享组件压缩文件。

[0160] 具体地,利用前端打包工具(如rollup),将步骤3生成的临时js文件作为入口文件,将输入的*.vue组件源码中的js、css、html、关系树进行自动打包,输出为可以通过浏览器<script>标签直接引入的js(umd模式),并将生成的js文件放入步骤1配置的输出口路径下,输出的转码后的js文件名为引入的*.vue组件文件名.umd.js(如输入share-icon.vue转码后的文件名为share-icon.umd.js)。利用gulp(可以是替换为其他任何文件流读取工具,如fs也可以)将经过转码后的输出口中的js文件作为输入口,读取文件内容的源码字符串并将其存放到临时变量content中进行转码。

[0161] 在一种可能的实施方式中,对临时变量content进行以下转码过程:

[0162] 1)创建三个临时内存数组变量:suffixContents(用于存放content串函数体头部的源码字符串)、sources(用于存放新的源码字符串数组)、tempFuncs(用于存放临时函数源码字符串的字符串数组);

[0163] 2)通过字符串

"use strict"

"use strict"

"use strict"

[0164] 3)将上一步获取到的源码字符串prefixContents从字符串

.render=function(

[0165] 4)解析上一步的源码字符数组rangeRenders,将数组第一个元素字符串值rangeRenders[0]直接追加到源码sources(通过push函数放入)数组中,从数组rangeRenders偏移量位置为1的位置开始遍历数组,将每一轮遍历函数中的遍历的源码字符串存放于临时变量rangeRender,遍历的位置存放于临时变量randerIndex;

[0166] 5)针对第4)步每轮的字符串值rangeRender进行解析。将rangeRender字符串从

.__file="

.__scopeId=

"

"

[0167] 6)读取第5)步中解析出的文件路径filePath映射的*.vue源码,并从读取的源码中解析出有效的template源码。第一步:利用nodejs读取文件的工具fs读取filePath下的*.vue文件源码字符串并存放到临时变量code中;第二步:从code中提取第一次出现

&lt;template&gt;+10

&lt; / template&gt;

source

"t_"+第4)步的遍历位置randerIndex

return通过javascript默认函数btoa和encoderURL对template变量值转码后得到的字符串值;

第5)步获取到的scopeId字符串 + ".template=decodeURI(atob(" +临时变量funcName的字符串值 + "()))" + 第5)步中获取到的临时变量prefixContent的字符串值

[0168] 7)通过第5)步遍历、第6)步解析生成新源码后,得到一个解析完整的suffixContents字符串变量、tempFuncs字符串数组变量(t函数源码字符串数组)、sources字符串数组变量,将3个变量按照以下规则进行拼接得到一个新的完整的js源码字符串并将字符串值存放到临时变量newContents中,拼接规则:

suffixContents +tempFuncs.join("") + sources.join("")

[0169] 8)将第7)步得到的新的拼接字符串源码newContents替换原来步骤5)的输入口文件内容(即将转换后的新源码字符串内容覆盖原来打包的各种.umd.js的源码内容)。

[0170] 进一步的,经过上述处理过程,将需要共享出去的共享组件(*.vue组件),完成了转码过程,转码后的文件可以供任何vue框架系统使用(其他项目用解码器进行解码使用)。

[0171] 下面将通过具体示例,来对本发明实施例中的前端组件的共享过程进行阐述:

[0172] 第一方面,按照如下流程在被引用共享*.vue组件项目中进行转码器(转码器包名:vue-encoder)的引入和使用:

[0173] 步骤1、安装转码器:npm install vue-encoder;

[0174] 步骤2、在被引用项目中创建gulpfile.js文件;

[0175] 步骤3、在gulpfile.js文件中引入转码器:

[0176] const Encoder = require('vue-encoder')

[0177] const encoder = new Encoder({

[0178] / / 配置转码器输入口路径

[0179] input: `src / globals / *.vue`;

[0180] / / 配置转码器输出口路径

[0181] output: 'public / globals';

[0182] })

[0183] exports.default = encoder;

[0184] 步骤4、执行转码命令:gulp;

[0185] 步骤5、命令执行完成后,在gulpfile.js文件目录配置的输出口文件夹下会有转码后的*.umd.js文件。

[0186] 第二方面,按照如下流程在引用项目中进行解码器(解码器包名:vue-decoder)的引入和使用(假设:转码后的js文件存放于url(http: / / 127.0.0.1 / example.umd.js)下):

[0187] 步骤1、安装解码器:npm install vue-decoder;

[0188] 步骤2、引入解码器:

[0189] app.use(Decoder, {

[0190] baseUrl: 'http: / / 127.0.0.1';

[0191] suffix: 'umd.js';

[0192] })

[0193] 步骤3、装载组件包含自动和手动装载两种方式,下面的两种装载方式的使用样例:

[0194] 1)自动装载共享组件(使用全局组件vue-decoder进行配置):

[0195] <vue-decoder url="http: / / 127.0.0.1 / example.umd.js">

[0196] 或<vue-decoder url="example">

[0197] 2)手动装载共享组件:

[0198] 第一步:装载共享组件:

[0199] $decoder.install("http: / / 127.0.0.1 / example.umd.js");

[0200] 或 $decoder.install("example");

[0201] 第二步:使用装载的共享组件(装载后就跟在项目中的其他全局组件是一样的):如在template使用:<example *** / >;

[0202] 步骤4、卸载共享组件:$decoder.uninstall("example")。

[0203] 进一步的,在通过解码器对共享组件进行动态引入、解码、注册且成功之后,可以直接将解码后的共享组件的组件信息,在前端进行渲染,并展示在图形用户界面上。

[0204] 值得注意的是,编码器在对共享组件(vue组件)进行打包时,与普通的打包js源码的方式之间的差别在于:该vue组件依赖的一些全局组件如果在引用项目中也同样包含这些全局组件(比如公共依赖的组件库element),那打包的时候就不用把公共依赖的这些组件库打包进去,极大的减少了转码后js的大小,进一步减少了共享组件共享的简洁性。

[0205] S103、基于解码后的共享组件的组件信息,渲染解码后的目标共享组件。

[0206] 在本发明实施例中,可以通过时渲染多个共享组件,共享组件的具体表现形式与共享组件的组件信息相关。

[0207] 示例性地,若是共享组件信息指示共享组件为一三角形箭头,在对该共享组件进行渲染时,渲染结果为在图形用户界面上展示一个三角形的箭头组件,并且若是共享组件信息指示该共享组件为可交互组件,在渲染三角形的箭头组件后,用户可以通过交互操作(例如,点击该三角形箭头)完成界面跳转等交互操作。

[0208] 本发明实施例提供的前端组件的共享方法,在前端渲染过程中当存在共享组件需求时,引入并装载解码器;控制解码器动态对共享组件压缩文件进行解码后,装载解码后的共享组件;其中,共享组件压缩文件是对转码后的文件存储到的网址进行访问获取的;共享组件压缩文件是通过转码器对共享组件进行转码后生成的;基于解码后的共享组件的组件信息,渲染解码后的目标共享组件。这样,通过转码器将共享组件转码打包,在前端渲染过程中,通过解码器动态访问转码后的共享组件压缩文件,直接对共享组件压缩文件进行解码引用,降低共享组件交叉引用时项目间的耦合程度,减少引用步骤,有助于提升组件共享的简洁性以及共享效率。

[0209] 基于同一发明构思,本发明实施例中还提供了与前端组件的共享方法对应的前端组件的共享装置,由于本发明实施例中的装置解决问题的原理与本发明实施例上述前端组件的共享方法相似,因此装置的实施可以参见方法的实施,重复之处不再赘述。

[0210] 请参阅图2、图3,图2为本发明实施例所提供的一种前端组件的共享装置的结构示意图之一,图3为本发明实施例所提供的一种前端组件的共享装置的结构示意图之二;其中,图3与图2所示的共享装置中一致的模块用实线表示,图3中所示的共享装置还包括的模块用虚线表示;如图2中所示,所述前端组件的共享装置200包括:

[0211] 解码器引入模块210,用于在前端渲染过程中当存在共享组件需求时,引入并装载解码器;

[0212] 组件装载模块220,用于控制所述解码器动态对共享组件压缩文件进行解码后,装载解码后的共享组件;其中,所述共享组件压缩文件是对转码后的文件存储到的网址进行访问获取的;所述共享组件压缩文件是通过转码器对共享组件进行转码后生成的;

[0213] 组件渲染模块230,用于基于解码后的共享组件的组件信息,渲染解码后的目标共享组件。

[0214] 在一种可能的实施方式中,如图3所示,所述共享装置200还包括组件卸载模块240,所述组件卸载模块240用于:

[0215] 卸载通过所述解码器解码注册的共享组件。

[0216] 在一种可能的实施方式中,如图3所示,所述共享装置200还包括组件转码模块250,所述组件转码模块250用于:

[0217] 引入所述转码器,并创建临时文件夹;其中,所述临时文件夹用于存储转码过程中生成的临时文件;

[0218] 针对于待转码的至少一个共享组件创建对应的临时文件;所述临时文件用于导入对应的共享组件;

[0219] 通过前端打包工具对生成的至少一个临时文件进行转码处理,得到至少一个初始转码共享组件文件;

[0220] 将各个初始转码共享组件文件调整为可访问的共享组件文件后,生成所述共享组件压缩文件。

[0221] 在一种可能的实施方式中,所述解码器动态对共享组件压缩文件进行解码的方式包括自动解码方式以及手动解码方式;

[0222] 当所述解码器动态对共享组件压缩文件进行解码的方式包括自动解码方式时,所述组件装载模块220在用于控制所述解码器动态对共享组件压缩文件进行解码后,装载解码后的共享组件时,所述组件装载模块220用于:

[0223] 当检测到引入所述解码器后创建的全局组件的属性发生变化时,自动判断引入所述解码器后创建的全局变量是否存在;

[0224] 若存在,检测是否存在历史被装载的共享组件;

[0225] 若存在历史被装载的共享组件,卸载历史被装载的共享组件,并控制所述解码器动态对共享组件压缩文件进行解码后,装载解码后的共享组件。

[0226] 在一种可能的实施方式中,所述组件装载模块220还用于:

[0227] 若不存在历史被装载的共享组件,通过所述手动解码方式控制所述解码器动态对共享组件压缩文件进行解码以及装载。

[0228] 在一种可能的实施方式中,所述组件装载模块220在用于通过所述手动解码方式控制所述解码器动态对共享组件压缩文件进行解码以及装载时,所述组件装载模块220用于:

[0229] 调用第一目标函数传入解码后待装载的共享组件的名称、回调函数以及装载参数;

[0230] 检测传入后的所述共享组件是否有组件名称或者所述装载参数是否为有效参数对象;

[0231] 若所述共享组件有组件名称且所述装载参数为有效参数对象,定义临时字符串,并确定所述临时字符串中包含文件名称信息;

[0232] 基于所述临时字符串构建并加载共享文件后,注册全局组件;

[0233] 在所述全局组件注册结束后,若根据所述回调函数确定不存在其他可回调的函数,结束装载过程。

[0234] 在一种可能的实施方式中,所述组件装载模块220用于通过以下步骤注册所述全局组件:

[0235] 检测待注册的全局组件中是否包含待注册组件信息;

[0236] 若所述待注册的全局组件中不包含待注册组件信息,调用第二目标函数将所述待注册组件信息注册到实例中的全局组件中;

[0237] 基于所述待注册组件信息中的名称信息,检测所述解码器中是否存在共享组件以及共享组件信息;

[0238] 若所述解码器中存在共享组件以及共享组件信息,基于所述共享组件信息完成所述全局组件的注册;

[0239] 若所述解码器中不存在共享组件以及共享组件信息,基于创建的临时变量指示的注册信息完成所述全局组件的注册。

[0240] 本发明实施例提供的前端组件的共享装置,在前端渲染过程中当存在共享组件需求时,引入并装载解码器;控制解码器动态对共享组件压缩文件进行解码后,装载解码后的共享组件;其中,共享组件压缩文件是对转码后的文件存储到的网址进行访问获取的;共享组件压缩文件是通过转码器对共享组件进行转码后生成的;基于解码后的共享组件的组件信息,渲染解码后的目标共享组件。这样,通过转码器将共享组件转码打包,在前端渲染过程中,通过解码器动态访问转码后的共享组件压缩文件,直接对共享组件压缩文件进行解码引用,降低共享组件交叉引用时项目间的耦合程度,减少引用步骤,有助于提升组件共享的简洁性以及共享效率。

[0241] 请参阅图4,图4为本发明实施例所提供的一种电子设备的结构示意图。如图4中所示,所述电子设备400包括处理器410、存储器420和总线430。

[0242] 所述存储器420存储有所述处理器410可执行的机器可读指令,当电子设备400运行时,所述处理器410与所述存储器420之间通过总线430通信,所述机器可读指令被所述处理器410执行时,可以执行如上述图1所示方法实施例中的前端组件的共享方法的步骤,具体实现方式可参见方法实施例,在此不再赘述。

[0243] 本发明实施例还提供一种计算机可读存储介质,该计算机可读存储介质上存储有计算机程序,该计算机程序被处理器运行时可以执行如上述图1所示方法实施例中的前端组件的共享方法的步骤,具体实现方式可参见方法实施例,在此不再赘述。

[0244] 所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。

[0245] 在本发明所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,又例如,多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些通信接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。

[0246] 所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。

[0247] 另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。

[0248] 所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个处理器可执行的非易失的计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-OnlyMemory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。

[0249] 最后应说明的是:以上所述实施例,仅为本发明的具体实施方式,用以说明本发明的技术方案,而非对其限制,本发明的保护范围并不局限于此,尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,其依然可以对前述实施例所记载的技术方案进行修改或可轻易想到变化,或者对其中部分技术特征进行等同替换;而这些修改、变化或者替换,并不使相应技术方案的本质脱离本发明实施例技术方案的精神和范围,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以权利要求的保护范围为准。< / script>

Claims

1. A method for sharing a front-end component, characterized in that: The sharing method includes: When there is a need for shared components during the front-end rendering process, the decoder is introduced and loaded; After controlling the decoder to dynamically decode the shared component compressed file, the decoded shared component is loaded; wherein the shared component compressed file is obtained by accessing the URL where the transcoded file is stored; the shared component compressed file is generated by transcoding the shared component by the transcoder; Rendering the decoded target shared component based on the component information of the decoded shared component; The decoder dynamically decodes the shared component compressed file in the following ways: automatic decoding and manual decoding; When the method in which the decoder dynamically decodes the shared component compressed file includes an automatic decoding method, the method of controlling the decoder to dynamically decode the shared component compressed file and then loading the decoded shared component includes: When it is detected that the property of the global component created after the introduction of the decoder has changed, automatically determining whether the global variable created after the introduction of the decoder exists; If it exists, check whether there is a shared component that has been loaded historically; If there is a shared component that has been loaded in the past, the shared component that has been loaded in the past is uninstalled, and the decoder is controlled to dynamically decode the shared component compressed file, and then the decoded shared component is loaded.

2. The sharing method according to claim 1, characterized in that: After detecting whether there is a shared component that has been loaded historically, the sharing method further includes: If there is no shared component that has been loaded historically, the decoder is controlled by the manual decoding method to dynamically decode and load the shared component compressed file.

3. The sharing method according to claim 2, characterized in that: The method of controlling the decoder to dynamically decode and load the shared component compressed file by the manual decoding method includes: Call the first target function to pass in the name of the decoded shared component to be loaded, the callback function and the loading parameters; Detect whether the shared component after being passed in has a component name or whether the loading parameter is a valid parameter object; If the shared component has a component name and the loading parameter is a valid parameter object, define a temporary string, and determine that the temporary string contains file name information; After building and loading the shared file based on the temporary string, register the global component; After the global component registration is completed, if it is determined according to the callback function that there is no other callback function, the loading process is terminated.

4. The sharing method according to claim 3, characterized in that: Register the global component by following these steps: Check whether the global components to be registered contain the information of the components to be registered; If the global component to be registered does not contain the component information to be registered, calling the second target function to register the component information to be registered into the global component in the instance; Based on the name information in the component information to be registered, detecting whether there is a shared component and shared component information in the decoder; If there are shared components and shared component information in the decoder, completing the registration of the global component based on the shared component information; If the shared component and the shared component information do not exist in the decoder, the registration of the global component is completed based on the registration information indicated by the created temporary variable.

5. The sharing method according to claim 1, characterized in that: The sharing method further comprises: Uninstalls the shared components registered by the decoder.

6. The sharing method according to claim 1, characterized in that: The transcoder is controlled to transcode the shared component to generate the shared component compressed file through the following steps: Introducing the transcoder and creating a temporary folder; wherein the temporary folder is used to store temporary files generated during the transcoding process; Creating a corresponding temporary file for at least one shared component to be transcoded; the temporary file is used to import the corresponding shared component; Transcoding the generated at least one temporary file using a front-end packaging tool to obtain at least one initial transcoded shared component file; After adjusting each initially transcoded shared component file to an accessible shared component file, the shared component compressed file is generated.

7. A front-end component sharing device, characterized in that: The sharing device comprises: The decoder import module is used to import and load the decoder when there is a need for shared components during the front-end rendering process; A component loading module, used to control the decoder to dynamically decode the shared component compressed file and then load the decoded shared component; wherein the shared component compressed file is obtained by accessing the URL where the transcoded file is stored; the shared component compressed file is generated by transcoding the shared component by the transcoder; A component rendering module, used for rendering a decoded target shared component based on the component information of the decoded shared component; The decoder dynamically decodes the shared component compressed file in the following ways: automatic decoding and manual decoding; When the method in which the decoder dynamically decodes the shared component compressed file includes an automatic decoding method, the component loading module is used to control the decoder to dynamically decode the shared component compressed file and load the decoded shared component, and the component loading module is used to: When it is detected that the property of the global component created after the introduction of the decoder has changed, automatically determining whether the global variable created after the introduction of the decoder exists; If it exists, check whether there is a shared component that has been loaded historically; If there is a shared component that has been loaded in the past, the shared component that has been loaded in the past is uninstalled, and the decoder is controlled to dynamically decode the shared component compressed file, and then the decoded shared component is loaded.

8. An electronic device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the front-end component sharing method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the front-end component sharing method according to any one of claims 1 to 6 are executed.

Citation Information

Patent Citations

  • Application program processing method and device

    CN106502736A

  • Rendering method and device for shared front-end component, equipment and storage medium

    CN111258675A