How to implement pattern online customization function in a small program

Xiaobian to share the function of how CANVAS implements the pattern online customization function, I believe that most people don’t know much, so share this article to everyone, I hope everyone is reading this article. Have a gain, let’s take a look at it!

Recently received such a need, requiring a universal background frame page based on Vue and Element-UI, as follows:

  1. High versatility, need to be used in more than forty subprams in the later period, so most places are configurable.

  2. requires the form of a scaffolding. Can npm Install

  3. The multi-page sign is required, and multi-page signs can be returned via the browser URL. And the page signs should maintain a history, you can return
  4. The component requires asynchronous loading, reducing the first screen loading time.
  5. It is obvious that this is an application of

    ERP
  6. . During JSP, etc. Classmates, you should be very familiar with multiple page signs.

That will come to talk about realization. Universality

This is not difficult It is nothing more than trouble, put all the data, all the data, put it in a

config

file. Then introduced in the frame page and bind to the corresponding position. There is a comparison here. The problem that is difficult to hit, that is, if all the data is bound to the Vue Data, due to a large amount of data, it will lead to performance issues. If it is separated, it will make the profile look relatively complicated, increase the learning of the later user cost. This piece should be seen in the specific project demand, because I temporarily on the performance requirements of the front end is not so high, so it is temporarily used to bind to the DATA scheme

to make a scaffold form The product has made the demand to make the form of the component, then release NPM package, which is convenient for later updates, only moreThe new npm is OK, no need to copy the paste replace each item, but based on this is a frame page, and the configurable item is very large, but also to achieve many considerations such as Tab multi-page tabs, and finally select the scaffolding program Even if this later upgrade will be slightly troublesome (initial solution is in a folder in a folder, directly replacing the folder), but relative to the component, it is better to maintain, and later can write later An updated scaffolding, after all, it is now too low for issuing an NPM tool.

The first time to develop a scaffold, read a lot of community posts, find most scaffolds, generally based on two forms, a file-based form, another Git-Clone-based form, After contrast, I think the file replication is a bit complicated. I actually only need a tool that can be installed, so git-clone form is still more suitable for me.

The following is the code of the scaffolding, although it is just a simple five-sixty line code, but check the information + pit, and spent a morning time. !

# / usr / bin / env nodeconst shell = require ( ‘shelljs’); const program = require ( ‘commander’); const inquirer = require ( ‘inquirer’); Const ora = Require (‘ORA’); const fs = Require (‘fs’); const path = required (‘PATH’); const spinner = ora (); const gitclone = Require (‘git-clone’) Const Chalk = Require (‘Chaalk’) Program .Version (‘1.0.0’, ‘-V, –Version’) .PARSE (Process.argv); Const QueSTIS = [{type: ‘Input’, Name: ‘Name’, Message: ‘Please enter the project name’, Default: ‘my-project’, validate: (name) => {if (/ ^ [AZ] + / .test (name)) {return true;} else {return ‘project name must begin with lowercase letters’;}}}] inquiR.Prompt (Questions) .Then ((DIR) => {DownloadTemplate (Dir.Name); }) Function DownloadTemplate (DIR) {// Judgment whether the directory already has let ishaSDir = fs.existssync (path.resolve (dir)); if (ishaSDir) {spinner.fail (‘The current directory already exists!’); Return False Spinner.Start (`The directory you selected is: $ {chalk.red (dir)}, data load, please wait …`); // Clone Template file gitclone (`https: // github. COM / Noahlam / Vue-Multi-Tab.git`, DIR, NULL, FUNCTION (ERR) {// Remove the useless file shell.rm (‘- rf’, `$ {dir} /. git`) Spinner. Succeed (‘project initialization success!’) // Run common command shell.cd (dir) spinner.start (`is helping you install dependencies …`); shell.exec (‘npm i’)Spinner.succeed (‘dependencies successfully!’) shell.exec (‘npm run dev’)}}

  If you have questions or interest, you can directly access Github Code TAB-CLI  
Implement multi-page tab

To implement multi-page sick, then Vue-Router is basically abolished, why? Vue-router switches a single component according to the URL, and the tab requires multiple sub-components inside the component, so the route cannot be competent (at least I think so, if you have a better plan, please do not enlighten me ).

The display of multiple tabs is actually not difficult. Element has a ready-made TAB component, so the old man wrote the code is a shuttle, and the sleeves are dry, and the rumor is awkward, write a test, no test Any problem, really don’t be too simple, lost to the product preview:

Copy the browser address to other places paste, TAB does not change correctly

    Tab needs to be jumped and can be returned.
  1. The first problem is relatively simple, handwritten a Hash-based
  2. pseudo route
  3. put the current Tab’s ID on the URL, then return, according to URL opens the corresponding Tab.

    TIP: About how to implement routing, please see my other blog to do a front-end route
second problem, probably the focus of this article, Here, you will explain the needs, each Tab can jump

in Tab , the jump here, there is much more differences to the Vue-Router, you have to Push, Replace, BACK, Can with parameters. “So how do you achieve it? First maintain a list of open Tab, then maintain an usefulComponent list (including parameters), can this probably realize? Of course, it is not, the components’ jump, the passage of the parameters, it is impossible to let the user to implement these methods, I choose to put a public object, and then mounted on Vue.Prototype. Then I like Vue. $ Router.xxxx (my name is Vue. $ TAB) can be used anywhere on the page, if you are interested in specific implementation methods, please click on the link ended in this article, go to my Github warehouse Check.

Components are asynchronously loaded

before only use Vue-Router-based asynchronous loading method, but this project does not use Vue-Router, how is it? The official document of Vue is written: vue.component (‘async-webpack-example’, // This `Import` function returns a` Promise` object () => Import ‘))

However, I tried it, I found an error, IMPORT could not be used here, change the request. No, I don’t know where I didn’t get it. If you just know that you just have time, please tell me, thank you! Next, see this article on SegmentFault, using WebPack’s Require.Ensure can implement

// The first string is the component name, the second is the component path, the third Is chunkname (if not specified, naming it is n.js, 2.js …. n.js) vue.component (‘Home “=> {Require.ensure ([], () => Resolve (REQUIRE (‘@ / views / index.vue’)), ‘Home’)})

  The above is how CANVAS is made to implement all the contents of the pattern online customization, thank you for reading! I believe everyone has a certain understanding, I hope to share the content of everyone, if you want to learn more knowledge, please pay attention to Tumi Yun Industry News Channel!  
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment