search
HomeWeb Front-endJS Tutorialvue builds an automatic website building project

vue builds an automatic website building project

Mar 23, 2018 pm 02:59 PM
Build a websiteautomaticproject

This time I will bring you Vue to build an automatic website building project. What are the precautions for building an automatic website building project with Vue. The following is a practical case, let’s take a look.

Written before

I have been using Jquery+Jquery-ui to do this project before. At that time, there was no design draft and no project requirements. Just because BOSS said something like this, I was like...Okay! I admit, I’m actually used to it, and it doesn’t matter anymore (it’s also helpless, hey)!!!

After a period of time, I made a demo, and BOSS was very satisfied, so I continued slowly Let's do it, for about two or three months, just focus on this. Later, the project was launched. Of course, because of the imperfection of the product, there were still some problems!

But it can basically meet the company's needs. Everything that can be edited can be edited. The component's background (including background image) color border box-shadow margin padding width height alignment (font and Internal elements of the component) border-radius font (font-size/font-family) and other basic elements can be changed at will. Of course, considering that it may not meet the company's needs, a custom style was added. function, and this can only be used by people who understand the front-end. There is no way, the demand will never keep up with the changes, so it is safer. Because everyone knows that the satisfaction and change of needs always precede ready-made needs

In addition to these basic changes, the unique changeable functions of each component are also basically complete, such as carousel image changes, The functions of carousel mode, controlling whether to carousel, etc. will not be introduced one by one here

Including later, because some elements within the component cannot be modified, the [Binding Modification] function was added, which is this After the function is selected, in the view interface, select the element that needs to be modified, and then you can modify it. This function is quite interesting

Having said so much, in fact, because it was done in a hurry, what was saved during storage was HTML, please don’t despise it (shame 0.0). This has always been a joke in my heart. Recently, BOSS has put forward some new ideas. There are quite a lot of things to add. After thinking about it, I decided to restructure the project

Considering that vue is responsive and basically pure data operations, we decided to rebuild this project using vue.

Development preparation

1. Use vue-cli to download the configured things
2. Because the drag and drop operation of generating components is involved, so Used vuedraggable and sortablejs.

Install vuedraggable sortablejs

npm install vuedraggable
npm install sortablejs

In the project, we only need to introduce vuedraggable. When sortablejs is involved, vuedraggable will load and call the methods in sortablejs. This is not ours. Things that need attention (if you want to know, you can go and see for yourself);

3. Install vuex, because it involves a lot of data interaction, and many components require some public data, so you don’t need to use vuex to manage it. , will bring more unnecessary trouble to development;

Install vuex

npm install --save vuex

4. Because there is no design draft, I boldly used the third-party UI library element-ui;

element-ui official website address

Install elememt

npm install element-ui
//为什么是element-ui而不是element?因为当时npm上已经有了element包了(我当时还觉得挺有意思的,0.0 好冷啊!!!)

5. Axios installation, which will be used later to interact with background data

Install axios

npm install --save axios

AlmostPreparation workThat’s it, let’s look at the project implementation next;

Start of the project

1. Configuration of files

-> Configuration of files in main.js

There are explanations in the pictures, you should be able to understand them ;

-> Configuration of sidebar drag component data

Because the file is too long, some have been deleted. Here is a simple one The format is for reference only, not as a standard;

There is a layout problem among components, so there must be layout components so that the components can be placed in the layout assembly, so that it is more flexible

-> vuexjs 状态管理中的js配置

说明:

1、因为用户在拖拽之后要实时保存到sessionStorage中, 所以再初始的时候要到sessionStroage中去取数据,防止突然刷新页面,还没有保存到数据库中,用户刚刚编辑的数据全部丢失的情况;
2、这里说明一下,可能考虑到用于已经提交了数据,所以用户关闭窗口之后,再次进来的时候,要结合后台给出的用户之前的数据,一起存储到sessionStorage中去,相信这一点大家肯定想的到的,这里善意提醒一下 0.0;
3、我这这里暂时放了四个参数,图中都有说明,我主要是将基本编辑做成了一个组件,会根据用户点击时哪个组件,而重新渲染数据给到编辑组件,从而可以实时对应到点击的组件去编辑;
4、editShow的作用就是控制编辑组件显示与否的,主要删除组件的时候,让编辑组件隐藏一下;点击其他组件的显示一下;

基本的配置就这些了,接下来就是真正的开发了;

2、项目开发开始

-> app.vue文件中该怎么写?

<template>
 <!--用的element-ui-->
 <el-container>
  <el-aside>
   <draggable>
    <p>
     </p>
<p>
      <i></i>
      <span>{{ list.title }}</span>
     </p>
    
   </draggable>
  <el-aside>
  <el-main>
   <section>
    <p>
     <span></span>
     <span></span>
    </p>
    <!--页面view区 -->
    <sort></sort>
    <p>
     <button>RS</button>
    </p>
   </section>
  </el-main>
  <el-aside>
   <!--组件编辑区域-->
   <baseedit></baseedit>
  </el-aside>
 </el-aside></el-aside></el-container> 
</template>
<script>
import DragApi from "@/dragapi/dragapi.js";
import Draggable from "vuedraggable";
import Sort from "@/view/Sort";
import BaseEdit from "@/view/BaseEdit";
export default {
 name: &#39;app&#39;,
 data(){
  return{
   dragData: {},
   dragOption: {
    group: {
     name: &#39;components&#39;, //这个很重要,其他的与之能产生关联的拖拽框就靠这name 一定要一致
     pull: &#39;clone&#39;, 
     put: false
    },
    sort: false //默然为true。这里我们只需要他拖拽,无需能拖动排序
   }
  }
 },
 components: {
  Draggable,
  Sort,
  BaseEdit
 },
 created(){
  //侧边栏拖拽列表数据
  //这里我只写了组件的数据进来,布局的暂时没放
  this.dragData = DragApi.configList[1].content;
 }
}
</script>

-> 来看看sort view视图区域组件

<template>
 <draggable>
  <!-- ui组件 -->
  <!--这里不懂的人,可以去vue官网看看动态组件-->
  <p>
  </p>
 </draggable>
</template>
<script>
 //利用vuex 辅助函数来操作vuexjs中的数据
 import { mapState,mapMutations } from &#39;vuex&#39;;
 //拖拽插件引入
 import Draggable from &#39;vuedraggable&#39;;
 //各个组件引入
 import Carousel from "@/components/Carousel.vue";
 import Btn from "@/components/Btn.vue";
 export default {
  name: &#39;Sort&#39;,
  components: {
   Draggable,Btn,Carousel
  },
  data(){
   return {
    sortOption: {
     group: {
      name: &#39;components&#39;, //前面说的name,在这里就起了作用,不一样,是不能放入的
      pull: true,
      put: true
     },
     sort: true,
     animation: 300 //给了个动画,看起来舒服些
    }
   }
  },
  computed:{
   ...mapState([&#39;editIndex&#39;,&#39;sortApi&#39;]),
  },
  watch:{
   sortApi:{
    handler(newVal,oldVal){
     window.sessionStorage.setItem(&#39;localData&#39;,JSON.stringify(newVal));
    },
    deep: true
   }
  },
  methods:{
   ...mapMutations([&#39;sortCp&#39;,&#39;addCp&#39;,&#39;setStyle&#39;,&#39;setCommon&#39;]),
   onSort(res){ //排序产生的事件
    if(res.from === res.to){
     this.sortCp(res);
    }
   },
   onAdd(res){//组件增加产生的事件
    this.addCp(res);
   },
   getIndex(index){
    this.setCommon({index: index,flag: true});
   }
  }
 }
</script>

-> 再来看看编辑组件

<template>
 <transition>
  <p> 0 && editShow === true">
   //组件特有编辑
   <el-tabs>
    <el-tab-pane>
     <p>
     </p>
    </el-tab-pane>
    <el-tab-pane>
     //公共样式编辑
     <el-collapse>
      <el-collapse-item>
       <el-form>
        <el-form-item>
         <el-color-picker> setStyle(value,item.style)"
          v-model="sortApi[editIndex].style[item.style]"
          show-alpha>
         </el-color-picker>
         <span>
          {{ sortApi[editIndex].style[item.style] }}
         </span>
        </el-form-item>
       </el-form>
      </el-collapse-item>
     </el-collapse>
    </el-tab-pane>
   </el-tabs>
  </p>
 </transition>
</template>
<script>
 import { mapState,mapMutations } from &#39;vuex&#39;;
 //这里我将组建特有的编辑栏,写成了一个组件,为什么不写在相应的组件一起了?
 //这里必须说明一下,主要是我没有想到方法,让他在同一组件内分离出来,单独将dom结构放在编辑栏这里,如果有大神知道
 //还望不吝赐教
 import BtnEdit from "@/components/BtnEdit.vue";
 
 export default{
  name: &#39;BaseEdit&#39;,
  components: {
   BtnEdit
  },
  data(){
   return{
    colorPicker: {
     type: &#39;颜色设置&#39;,
     name: &#39;Picker&#39;,
     content:[
      {
       title: &#39;背景颜色&#39;,
       style: &#39;background&#39;
      },
      {
       title: &#39;字体颜色&#39;,
       style: &#39;color&#39;
      }
     ]
     
    },
    activeName: &#39;first&#39;
   }
  },
  
  computed:{
   ...mapState([&#39;editIndex&#39;,&#39;sortApi&#39;,&#39;editShow&#39;])
  },
  methods:{
   setStyle(value,style){
    //根据上面传入的style属性,实时改变现有的值
    this.$set(this.sortApi[this.editIndex].style,style,value);
   }
  }
 }
</script>

-> 选出一个组件来看看里面是怎么配置的

//按钮组件,其实里面很简单
//组件的对应的编辑组件,里面内容和这个也差不多,下面就不写了
<template>
 <p>
  <el-button>
   {{ content.text }}
  </el-button>
  //因为每个组件都有删除功能,所以写成了一个组件
  <deletecp></deletecp>
 </p>
</template>
<script>
 import DeleteCp from "@/components/DeleteCp";
 export default {
  name: &#39;Btn&#39;,
  props: { //父组件传入的参数
   content: Object,
   oStyle: Object,
   aIndex: Number
  },
  components: {
   DeleteCp
  },
  data(){
   return{
    btnModel: &#39;btn-model&#39;
   }
  }
 }
</script>

->最后来看看删除组件吧

<template>
 <p>
  </p>
<p></p>
  <el-dialog>
   <p>
    </p>
<p></p>
    <p>此操作将删除该模块, 是否继续?</p>
   
   <span>
    <el-button>取 消</el-button>
    <el-button>确 定</el-button>
   </span>
  </el-dialog>
 
</template>
<script>
 import { mapMutations } from "vuex";
 export default {
  name: &#39;oText&#39;,
  props: {
   aIndex: Number
  },
  data(){
   return{
    //这两个参数是弹框的参数
    dialogVisible: false,
    appendToBody: true 
   }
  },
  methods:{
   ...mapMutations([&#39;deleteCp&#39;,&#39;setCommon&#39;]),
   dailogStatu(){
   //主要是控制弹窗出来,并且显示该组件对应的编辑栏
    this.dialogVisible = true;
    this.setCommon({flag: true,index: this.aIndex})
   },
   onRemove(index){
    //点击确定删除对应的组件
    let flag = false;
    this.deleteCp(index);
    this.dialogVisible = false;
    this.$message({
     message: &#39;该模块已删除 !&#39;,
     type: &#39;success&#39;
    });
    this.setCommon({flag: false,index: 0})
   }
  }
 }
</script>


-> 来看看效果图吧

效果图展示

结束语

好了,今天写了很多了,最后我们来梳理一下思路:

1、首先配置左侧的拖拽组件
2、配置vuex中的数据
3、app.vue中配置
4、编辑组件的配置
5、各种数据的传递与依赖

其实每个项目,都需要一个清晰的路线,这样才能很好的开发下去,所以我的建议是,在拿到项目的时候,千万不要一股脑的去写,一定要想好怎么做,以及突发事情的发生(比如突来的需求变更),这样既方便了我们自己,也方便了后来维护的人,也阻止了不必要的麻烦

谢谢大家的耐心的阅读,毕竟这只是一个大概的介绍,肯定存在很多不足,如果大家有建议,欢迎留言交流,也希望大家多多支持脚本之家。

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

JS如何做出公共子序列

datepicker插件监听输入框

ejsExcel模板在Vue.js中的使用

D3.js创建物流地图

The above is the detailed content of vue builds an automatic website building project. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

The Role of C/C   in JavaScript Interpreters and CompilersThe Role of C/C in JavaScript Interpreters and CompilersApr 20, 2025 am 12:01 AM

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript in Action: Real-World Examples and ProjectsJavaScript in Action: Real-World Examples and ProjectsApr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

JavaScript and the Web: Core Functionality and Use CasesJavaScript and the Web: Core Functionality and Use CasesApr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding the JavaScript Engine: Implementation DetailsUnderstanding the JavaScript Engine: Implementation DetailsApr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: The Learning Curve and Ease of UsePython vs. JavaScript: The Learning Curve and Ease of UseApr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python vs. JavaScript: Community, Libraries, and ResourcesPython vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.