创建VUE项目的步骤:

npm install vue-cli -g

vue init webpack myproject

cd myproject

npm run dev

组件:它是可扩展的html

里面包括:

<template></template>

<script></script>

<style></style>

VUE框架的特性:能够实现热重载

import 和require的区别:

import 一定要放在文件顶部

它相当于一个指针引用了文件,并没有把文件包含进来了,需要调用时才引入

require:

可以放在文件中任何位置

它是把文件直接包含进来

设置文件路由的流程:

1)建立组件(.vue文件)

2)配置路由(index.js 文件中的配置)

3)<router-link></router-link>

4)<router-view></router-view>

5)import 包名 from ‘’组件路径''

6)components 进行注册

vue-resource:实现异步数据加载(已经弃用)

axios:实现异步数据加载

Vue组件的生命周期:

1)定义Vue对象并实例化

2)created函数

3)编译muban

4)把HTML元素渲染到页面当中

5)mounted函数

6)如果有元素的更新,就执行updated函数

7)销毁实例

代码如下:(有点小bug)

ALL.vue

<template>
<div class='box'>
<ul>
<li v-for='item in arr'>
<div class='p1'>
<router-link :to="{path:'/detail',query:{ids:item.id}}">{{item.content}} </router-link>
</div>
<div class="p2">
<img :src="item.imgUrl">
</div>
</li> </ul> </div>
</template> <script>
export default {
name: 'HelloWorld',
data () {
return {
arr: []
}
},
mounted () {
var url = '../../static/news.json'
var self=this;
this.$axios.get(url)
.then(function (response) {
console.log(response.data.result.data);
self.arr = response.data.result.data;
})
.catch(function (error) {
console.log(error);
})
}
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
} ul {
list-style-type: none;
padding: 0;
} li {
display: inline-block;
margin: 0 10px;
} a {
color: #42b983;
}
.box{
width: 980px;
}
.p1{
float:left;
width:780px;
}
img{
float:right;
}
</style>

DETAIL.vue

<template>
<div class="box">
<h1>我是详情页{{id}}</h1>
<ul>
<li>
<div class="p1">
{{obj.content}}
</div>
<div class="p2">
<img :src="obj.imgUrl">
</div>
</li> </ul>
</div>
</template> <script>
export default {
name: 'Detail',
data () {
return { obj: {},
id: this.$route.query.ids
}
},
mounted () {
var url = '../../static/news.json'
var self = this;
this.$axios.get(url, {
params: {id: this.id}
})
.then(function (response) {
console.log(response.data.result.data[0])
self.obj = response.data.result.data[0];
})
.catch(function (error) {
console.log(error); })
} }
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
} ul {
list-style-type: none;
padding: 0;
} li {
display: inline-block;
margin: 0 10px;
} a {
color: #42b983;
}
</style>

DUANZI.vue

<template>
<div>
<h>我是段子</h>
</div>
</template> <script>
export default {
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>

NaveList.vue

<template>
<div>
<router-link to='/'>首页</router-link>
<router-link to='/news'>新闻</router-link>
<router-link to='/duanzi'>段子</router-link>
<router-link to='/detail'>详情页</router-link>
</div>
</template> <script>
export default {
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>

NEWS.vue

<template>
<div>
<h>我是新闻</h>
</div>
</template> <script>
export default {
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>

index.js

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import ALL from '@/components/All'
import NEWS from '@/components/NEWS'
import DUANZI from '@/components/DUANZI'
import DETAIL from '@/components/DETAIL' Vue.use(Router) export default new Router({
routes: [
{
path: '/ll',
name: 'HelloWorld',
component: HelloWorld
},
{
path: '/',
name: 'ALL',
component: ALL
},
{
path: '/news',
name: 'news',
component: NEWS
}
,
{
path: '/duanzi',
name: 'duanzi',
component: DUANZI
},
{
path: '/detail',
name: 'detail',
component: DETAIL
}
]
})

App.vue

<template>
<div id="app">
<img src="./assets/logo.png">
<NaveList></NaveList> <router-view></router-view>
</div>
</template> <script>
import NaveList from './components/NaveList'
export default {
name: 'App',
components: {NaveList} }
</script> <style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>

main.js

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import VueAxios from 'vue-axios' Vue.prototype.$axios = axios //Vue.config.productionTip = false /* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: {App},
template: '<App/>'
})

Vue仿抽屉的更多相关文章

  1. vue-resource使用 (vue仿百度搜索)

    1.this.$http.get()方法2.this.$http.post()方法3.this.$http.jsonp()方法 (vue仿百度搜索) 在输入框中输入a, 然后在百度f12 ==> ...

  2. vue 仿今日头条

    vue 仿今日头条 为了增加移动端项目的经验,近一周通过 vue 仿写今日头条,以下就项目实现过程中遇到的问题以及解决方法给出总结,有什么不正确的地方,恳请大家批评指正^ _ ^!,代码仓库地址为 g ...

  3. Nuxt|Vue仿探探/陌陌卡片式滑动|vue仿Tinder拖拽翻牌效果

    探探/Tinder是一个很火的陌生人社交App,趁着国庆假期闲暇时间倒腾了个Nuxt.js项目,项目中有个模块模仿探探滑动切换界面效果.支持左右拖拽滑动like和no like及滑动回弹效果. 一览效 ...

  4. vue仿微信网页版|vue+web端聊天室|仿微信客户端vue版

    一.项目介绍 基于Vue2.5.6+Vuex+vue-cli+vue-router+vue-gemini-scrollbar+swiper+elementUI等技术混合架构开发的仿微信web端聊天室— ...

  5. vue聊天室|h5+vue仿微信聊天界面|vue仿微信

    一.项目简介 基于Vue2.0+Vuex+vue-router+webpack2.0+es6+vuePhotoPreview+wcPop等技术架构开发的仿微信界面聊天室——vueChatRoom,实现 ...

  6. Vue仿微信app页面跳转动画

    10:14:11独立开发者在开发移动端产品时,为了更高效,通常会使用Web技术来开发移动端项目,可以同时适配Android.iOS.H5,稍加改动还可适配微信小程序. 在使用Vue.js开发移动端页面 ...

  7. 使用 vue 仿写的一个购物商城

    在学习了 vue 之后,决定做一个小练习,仿写了一个有关购物商城的小项目.下面就对项目做一个简单的介绍. 项目源码: github 项目的目录结构 -assets 与项目有关的静态资源,包括 css, ...

  8. vue 仿zTree折叠树

    需求: vue实现仿zTree折叠树,此文章仅作为记录文档. 实现: <template> <div class="line-tree"> <div ...

  9. Vue 仿B站滑动导航

    仿照B站制作的滑动导航功能,进行了部分优化,例如可定制默认选中元素,并将选中元素居中显示,可动态更改数据,可定制回调函数取的下标和选中元素内容,可根据需求制作N级联动 已开发成插件,使用方法与源码请前 ...

随机推荐

  1. EntityFramework附加实体

    //0.0创建修改的 实体对象 Models.BlogArticle model = new BlogArticle(); model.AId = 12; model.ATitle = "新 ...

  2. hiveServer2 和 metastore的一点解读。

    刚看了hive官网的文档,对于一些概念结合自己的经验,似乎又多了一些理解,想一想还是记下来的好,一来我是个有些健忘的人,过一段时间即便忘了,循着这个帖子,也能快速把知识点抓起来:二来或许对别人也有些启 ...

  3. Hive基础之Hive与关系型数据库的比较

    Hive与关系型数据库的比较     使用Hive的CTL(命令行接口)时,你会感觉它很像是在操作关系型数据库,但是实际上,Hive和关系型数据库有很大的不同.       1)Hive和关系型数据库 ...

  4. JavaSE 常用类与其方法

    1.基本数据类型比较用:== 2.引用数据类型比较用:equals方法 如果引用数据类型使用==比较的话,比较的是地址值 toString类 对象调用toString()需要重写本方法: 在封装类中, ...

  5. es6中的Promise学习

    关于Promise Promise实例一旦被创建就会被执行 Promise过程分为两个分支:pending=>resolved和pending=>rejected Promise状态改变后 ...

  6. python爬虫入门---第三篇:保存一张图片

    import requests import os url = 'http://imgsrc.baidu.com/forum/w%3D580%3B/sign=749ed018cecec3fd8b3ea ...

  7. React中props和state相同点和不同点

    朋友们,我想死你们了,最近这几天忙着和病魔作斗争所以没怎么写博客,今天感觉好点了,赶紧来写一波,就是这木敬业. 今天我们来讨论讨论props和state相同点和不同点 首先我来概要说明一下这两者 pr ...

  8. Python 基于python操纵redis入门介绍

    基于python操纵redis入门介绍 by:授客  QQ:1033553122 测试环境 redis-3.0.7 CentOS 6.5-x86_64 python 3.3.2 基于Python操作R ...

  9. loadrunner 脚本开发-int型变量和字符串的相互转换

    脚本开发-int型变量和字符串的相互转换 by:授客 QQ:1033553122 字符串转化为int型变量 Action2() { int j = 0; j = atoi("12345&qu ...

  10. unicode编码和utf8编码的区别

    编码格式不同在数据的传输和显示会有很大的影响.最近在使用的过程中发现一些网络文件 传输的编码格式问题,会影响文件的正常传输,于是查看了一下网上的资料,自己也写一篇 小总结. uicode是万国码,用1 ...