(23)打鸡儿教你Vue.js
实例:
模板语法
vue-router,vuex以及调式方法介绍
打包部署:
npm run build
Webpack 目前无论在求职还是工作中,使用越来越普及。而想要学懂,学会Webpack更绝非易事。
<template>
<div>
<p>标题</p>
<input type="text" v-model="title">
<p>内容</p>
<input type="text" v-model="content">
<div class="btn" @click="add()">添加</div>
</div>
</template>
<script>
import store from '@/store'
export default {
name: "Add",
store,
data () {
return {
title: '',
content: ''
}
},
methods: {
add () {
store.commit('addItem',{
title: this.title,
content: this.content
})
this.title = ''
this.content = ''
this.$router.push('/home/list')
}
}
}
</script>
<style scoped>
</style>
Add.vue
<template>
<div>
<router-view />
<ul class="footer">
<li class="icons"><router-link :to="{name: 'list'}">新闻列表</router-link></li>
<li class="icons"><router-link :to="{name: 'user'}">个人中心</router-link></li>
</ul>
</div>
</template>
<script>
export default {
name: "Home"
}
</script>
<style scoped lang="scss">
li {
list-style: none;
}
.footer {
position: fixed;
width: 100%;
height: 60px;
line-height: 60px;
left: 0;
bottom: 0;
display: flex;
flex-flow: row nowrap;
justify-content: space-around;
}
.icons {
font-size: 16px;
flex: 1;
text-align: center;
border-top: 1px solid #42b983;
a {
color: #42b983;
display: block;
&.active {
color: #fff;
background: #42b983;
}
}
}
</style>
Home.vue
<template>
<div>info</div>
</template>
<script>
export default {
name: "Info"
}
</script>
<style scoped>
</style>
Info.vue
<template>
<div>
<ul>
<li v-for="(item, index) in pageLists" :key="index">
{{item.title}}-{{item.content}}
</li>
</ul>
</div>
</template>
<script>
import store from '@/store'
export default {
name: "List",
store,
computed: {
pageLists () {
return store.state.lists
}
}
}
</script>
<style scoped>
</style>
List.vue
<template>
<div>
<form action="" v-if="!isReg">
<div>用户名:</div>
<input type="text" v-model="name">
<div>密码:</div>
<input type="password" v-model="password">
<div>
<button type="button" @click="login()">登录</button>
<button type="button" @click="reg()">注册</button>
</div>
</form>
<form action="" v-else>
<div>用户名:</div>
<input type="text" v-model="name">
<div>密码:</div>
<input type="password" v-model="password">
<div>再次输入密码:</div>
<input type="password" v-model="repeat">
<div>
<button type="button" @click="addUser()">确定</button>
<button type="button" @click="cancel()">取消</button>
</div>
</form>
</div>
</template>
<script>
export default {
name: "Login",
data () {
return {
isReg: false,
name: '',
password: '',
repeat: ''
}
},
methods: {
login () {
if (localStorage.getItem("name") === this.name && localStorage.getItem("password") === this.password){
this.name = ''
this.password = ''
this.$router.push('/home/list')
}else{
alert('用户名密码不正确')
}
},
reg () {
this.isReg = true
},
cancel () {
this.isReg = false
},
addUser () {
if (this.password === this.repeat){
localStorage.setItem('name', this.name)
localStorage.setItem('password', this.password)
this.name = ''
this.password = ''
this.isReg = false
}else{
alert('两次密码输入不一致')
}
}
}
}
</script>
<style scoped>
</style>
Login.vue
<template>
<div>user</div>
</template>
<script>
export default {
name: "User"
}
</script>
<style scoped>
</style>
User.vue
<template>
<div id="app">
<router-view/>
</div>
</template>
<style lang="scss">
* {
padding: 0;
margin: 0;
}
</style>
App.vue
import Vue from 'vue'
import Router from 'vue-router'
import Login from './views/Login.vue'
import Home from './views/Home.vue'
Vue.use(Router)
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
linkActiveClass: 'active',
routes: [
{
path: '/',
name: 'login',
component: Login
},
{
path: '/home',
name: 'home',
component: Home,
children: [
{
path: 'list',
name: 'list',
component: () => import(/* webpackChunkName: "list" */ './views/List.vue')
},
{
path: 'user',
name: 'user',
component: () => import(/* webpackChunkName: "user" */ './views/User.vue')
},
]
},
{
path: '/add',
name: 'add',
component: () => import(/* webpackChunkName: "add" */ './views/Add.vue')
}
// {
// path: '/about',
// name: 'about',
// // route level code-splitting
// // this generates a separate chunk (about.[hash].js) for this route
// // which is lazy-loaded when the route is visited.
// component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
// }
]
})
router.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
lists: []
},
mutations: {
addItem (state, value) {
state.lists.push(value)
}
},
actions: {
}
})
store.js
基础使用
认识Webpack
了解模块打包
多种Webpack安装方式及最佳方案
配置
命令行
核心知识
认识Loader
打包静态资源
plugins的概念及打包
SourceMap 应用与配置
WebpackDevServer
热模块更新
Babel 配置
进阶
Tree Shaking
Webpack中的分片打包
SplitChunksPlugin
懒加载和chunk
打包分析,Preloading, Prefetching
CSS 文件的代码分割
浏览器缓存
Shimming、环境变量使用方法
原理分析与扩展
自定义loader
自定义plugin
Webpack打包原理全分析
Webpack源码设计原理
全面性能优化
单页应用
多页应用
React
Vue
Typescript
ES6
PWA
EsLint
性能优化
使用过 Webpack ,做过
简单配置尝试
了解 JS 基础语法
使用过类似于 Webpack 这样的打包工具
对NodeJS有所理解
使用webpack
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
new MyAwesomeWebpackPlugin()
]
}
}
请点赞!因为你的鼓励是我写作的最大动力!
吹逼交流群:711613774
(23)打鸡儿教你Vue.js的更多相关文章
- (29)打鸡儿教你Vue.js
web阅读器开发 epub格式的解析原理 Vue.js+epub.js实现一个简单的阅读器 实现阅读器的基础功能 字号选择,背景颜色 有上一页,下一页的功能 设置字号,切换主题,进度按钮 电子书目录 ...
- (26)打鸡儿教你Vue.js
weex框架的使用 1.weex开发入门 2.weex开发环境搭建 3.掌握部分weex组件模块 4.了解一些vue基本常见语法 5.制作一个接近原生应用体验的app weex介绍 安装开发环境 We ...
- (22)打鸡儿教你Vue.js
vue.js 单页面,多页面 Vue cli工具 复杂单页面应用Vue cli工具 交互设计,逻辑设计,接口设计 代码实现,线上测试 git clone,git int 创建分支,推送分支,合并分支 ...
- (21)打鸡儿教你Vue.js
组件化思想: 组件化实现功能模块的复用 高执行效率 开发单页面复杂应用 组件状态管理(vuex) 多组件的混合使用 vue-router 代码规范 vue-router <template> ...
- (19)打鸡儿教你Vue.js
了解vue2.x的核心技术 建立前端组件化的思想 常用的vue语法 vue-router,vuex,vue-cli 使用vue-cli工具 Vue框架常用知识点 vue核心技术 集成Vue 重点看,重 ...
- (18)打鸡儿教你Vue.js
介绍一下怎么安装Vue.js vue.js Vue 不支持 IE8 及以下版本,因为 Vue 使用了 IE8 无法模拟的 ECMAScript 5 特性. Vue.js是一个渐进的,可逐步采用的Jav ...
- (17)打鸡儿教你Vue.js
vue-router <a class="list-group-item" v-link="{ path: '/home'}">Home</a ...
- (15)打鸡儿教你Vue.js
组件化vue.js 组件单向绑定 组件双向绑定 组件单次绑定 创建组件构造器 注册组件 使用组件 Vue.extend() Vue.component() 使用组件 <div id=" ...
- (13)打鸡儿教你Vue.js
一小时复习 vue.js是一个JavaScriptmvvm库,是以数据驱动和组件化的思想构建的,相比angular.js,vue.js提供了更加简洁,更加容易理解的api,如果习惯了jquery操作d ...
- (12)打鸡儿教你Vue.js
组件 语法格式如下: Vue.component(tagName, options) <tagName></tagName> <div id="app" ...
随机推荐
- idea多级目录不展开的问题
遇见了一个坑,idea新建的包,和它的上级包重叠在了一起,无法形成树状结构 原因呢,还是因为自己的不细心了,解决方案很简单,下面的是原情况 解决方案,点击左侧栏右上角的设置图表,注意看红框内 把第一行 ...
- C# 生成随机的6位字母,包含大小写
今天自己做项目需要生成随机的6位字母,于是自己写了一个,下面代码是可以生成任意位数字母的. string _zimu = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefg ...
- 转 如何在调用WCF服务之前弹出一个确认对话框
自定义InteractiveChannelInitializer(InvocationConfirmationInteractiveChannelInitializer)定义如下.我们在BeginDi ...
- 【洛谷 P4302】 [SCOI2003]字符串折叠(DP)
题目链接 简单区间dp 令\(f[i][j]\)表示\([i,j]\)的最短长度 先枚举区间,然后在区间中枚举长度\(k\),看这个区间能不能折叠成几个长度为\(k\)的,如果能就更新答案. #inc ...
- SAP官网发布的react教程
大家学习React的时候,用的是什么教程呢?Jerry当时用的阮一峰博客上的入门教程,因为React使用的JSX语法并不是所有的浏览器都支持,所以还得使用browser.js在浏览器端将JSX转换成J ...
- MySQL Replication--修复从库上单个数据库的数据
问题描述 由于运维失误,从库未及时设置read_only,导致从库上某库数据被修改,由于整个实例数据量较大,重做成本较高,而该数据库数据较少,因此考虑如何修复该数据库的数据. 操作前提 1.复制使用位 ...
- Mybatis,返回Map的时候,将Map内的Key转换为驼峰的命名
每次使用mybatis的时候,简单的连表查询,用Map接收的时候,都是像DB定义的字段一样,类似以下 student_name,student_id,没有转换为驼峰,但是又不能因为这一个定义一个jav ...
- edgex0.7.1_1.0.1的X86编译和交叉编译
一. X86编译 1. 安装zeromq库 根据setup script安装: wget https://github.com/zeromq/libzmq/releases/download/v4.2 ...
- ASP.NET Core3.0 中的运行时编译
运行时编译 通过 Razor 文件的运行时编译补充生成时编译. 当 .cshtml 文件的内容发生更改时,ASP.NET Core MVC 将重新编译 Razor 文件 . 通过 Razor 文件的运 ...
- 十分钟了解pandas
十分钟掌握Pandas(上)--来自官网API 一.numpy和pandas numpy是矩阵计算库,pandas是数据分析库,关于百度百科,有对pandas的介绍. pandas 是基于NumPy ...