Roam Tang

  • 主页
  • 随笔
  • 归档
  • 我
所有文章 友链 关于我

undefined

  • 主页
  • 随笔
  • 归档
  • 我

Vue小结

2016-11-24

试着用Vue做了一个小东西,总结一下,很多都是官网有的,只是记录下了作为一个学习笔记吧。

Vuejs 组件

组件的使用,需要先注册再使用。

1
Vue.component('componentName',{ /*component*/ });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Vue.component('mine',{
template:'#mineTpl',
props:['name','title','city','content']
});

var v=new Vue({
el:'#vueInstance',
data:{
name:'zhang',
title:'this is title',
city:'Beijing',
content:'these are some desc about Blog'
}
});

指令

指令是指带有v-前缀的特殊属性,当表达式的值改变时,将其产生的连带影响,响应式的作用于DOM,指令可以有参数(指令只有以冒号表示)和修饰符(以.修饰)

1
2
3
4
5
6
var myHeader = {
template: "<p v-html = 'test' v-on:keydown.enter = ''><my-header-child></my-header-child></p>",
components:{
"my-header-child":myHeaderChild
}
}

指令keep-alive

如果把切换出去的组件保留在内存中,可以保留它的状态或避免重新渲染。为此可以添加一个keep-alive指令

1
<component :is='curremtView' keep-alive></component>

属性

计算属性

computed计算属性 选项会被缓存
也可以通过调用方法来计算属性,使得每次的属性都是重新调用生成的
watch–监听属性变化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<input type = "text" v-model = "myVal">
{{ myValueWithoutNum }}
{{ getMyValWithoutNum() }}
export default {
data () {
return {
myVal:''
}
},
watch:{
myVal:function(val,oldVal) {
console.log(val,oldVal);
}
},
computed:{
myValueWithoutNum () {
return this.myVal.replace(/\d/g,'');//删掉所有数字
}
},
methods:{
getMyValWithoutNum (){
return this.myVal.replace(/\d/g,'');//删掉所有数字
}
}
}

事件绑定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<button @click="addItem">addItem</button>
<button @click="toogle">toogle</button>
export default {
data () {
return {
hello:'<span>hello world</span>',
link:'http://www.baidu.com',
className:['red-font','big-font'],
hasError:false,
classA:'hello',
classB:'world',
isPartA:true,
list:[
{
name: 'apple',
price: 34
},
{
name: 'banana',
price: 34
},
]
}
},
methods:{
addItem () {//es6缩写,原为:addItem:function(){}
Vue.set(this.list,1,{
name:'pinaapple',
price:231
})
},
toggle () {
this.isPartA = !this.isPartA
}
}
}

css只在当前组件中起作用

在每一个vue组件中都可以定义各自的css,js,如果希望组件内写的css只对当前组件起作用,只需要在style中写入scoped,即

1
<style scoped></style>

vuejs循环插入图片

1
2
3
<div class="bio-slide" v-for="item in items">   
<img v-bind:src="item.image">
</div>

vuejs中过渡动画

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
.zoom-transition {
width:60%;
height:auto;
position: absolute;
left:50%;
top:50%;
transform: translate(-50%,-50%);
-webkit-transition: all .3s ease;
transition: all .3s ease;
}
.zoom-enter, .zoom-leave {
width:150px;
height:auto;
position: absolute;
left:20px;
top:20px;
transform: translate(0,0);
}

就这样吧,有时间把Vuex Vue Router 一起写一篇详细的。

  • 前端
  • JavaScript
  • Vue

扫一扫,分享到微信

微信分享二维码
学习资料整理
让你的Vim支持ES6和React
  1. 1. Vuejs 组件
  2. 2. 指令
  3. 3. 指令keep-alive
  4. 4. 属性
    1. 4.1. 计算属性
    2. 4.2. 事件绑定
  5. 5. css只在当前组件中起作用
  6. 6. vuejs循环插入图片
  7. 7. vuejs中过渡动画
© 2023 Roam Tang 沪ICP备2022034513号
Hexo Theme Yilia by Litten
  • 所有文章
  • 友链
  • 关于我

tag:

  • 前端
  • 优化
  • JavaScript
  • 碎碎念
  • 生活
  • curl
  • linux
  • Css
  • Web
  • Performance
  • 性能
  • github
  • git
  • Linux
  • FTP
  • iptables
  • 防火墙
  • React
  • webpack
  • Mac
  • 快捷键
  • tips
  • Redis
  • 数据库
  • shadowsocks
  • software
  • Vue
  • ExtractTextPlugin
  • MiniCssExtractPlugin
  • Unit Test
  • Ember
  • hexo
  • jQuery
  • deploy
  • nodejs
  • webpack-bundle-analyzer
  • 编辑器
  • 环境
  • tool
  • ES6
  • gitment
  • comment
  • OAuth
  • Http
  • Docker
  • Rails
  • Ruby
  • Vuejs
  • Webpack
  • CSS Module
  • PostCSS
  • Karma
  • chai
  • mocha
  • enzyme
  • sinon
  • React Router
  • NodeJs
  • PhantomJs
  • Font-Awesome
  • Sublime
  • 柯里化
  • Vim
  • Syntastic

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • 友情链接1
  • 友情链接2
  • 友情链接3
  • 友情链接4
  • 友情链接5
  • 友情链接6
热爱生活的小光头!
2013年毕业于上海市同济大学软件工程学院,
现就职于SAP!