首页 / VUE / 使用Vue.js有哪些注意事项
使用Vue.js有哪些注意事项
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用Vue.js有哪些注意事项,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3499字,纯文字阅读大概需要5分钟。
内容图文
这次给大家带来使用Vue.js有哪些注意事项,使用Vue.js的注意事项有哪些,下面就是实战案例,一起来看一下。1.传递参数时,第二个参数要与前面的逗号有一个空格
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(items))
2. 注意空格
正确格式
<script>import Store from './store'console.log(Store)export default { ... }</script> 错误格式 <script> import Store from './store' console.log(Store)export default { ... }</script>
3. 父向子组件传参
父组件中
//模板中<template> <div id="app"> //之前老版本 <conponent-a msgfromfather="父亲传给儿子!"></conponent-a> <ConponentA msgfromfather="父亲传给儿子!"></ConponentA> </div></template>//Js<script>export default { //注册ConponentA components: {ConponentA}, }</script>
子组件中
<template> <div class="hello"> <h1>{{ msg }}</h1> <button v-on:click="onClickMe()">点我啊,小样儿</button> </div></template><script> export default { data () { return { msg: 'hello from component A!' } }, //props 可以是数组或对象,用于接收来自父组件的数据 props: ['msgfromfather'], methods: { onClickMe: function () { //打印从父组件传过来的值 console.log(this.msgfromfather) } } }</script><style scoped> h1 { font-weight: normal; }</style>
4. 子向父组件传参
儿子告诉父亲 需要使用vm.$emit 和vm.$on 触发事件和监听事件
子组件中
<template> <div class="hello"> <h1>{{ msg }}</h1> <h1>{{msgfromfather}}</h1> <button v-on:click="onClickMe()">点我啊,小样儿</button> </div></template><script> export default { data () { return { msg: 'hello from component A!' } }, methods: { onClickMe: function () {// 子传父 触发当前实例上的事件 this.$emit('child-tell-me-something', this.msg) } } }</script><style scoped> h1 { font-weight: normal; }</style>
父组件中
<template> <div id="app"> <p>child tells me: {{childWorlds}}</p> <ConponentA msgfromfather="父亲传给儿子!" v-on:child-tell-me-something="listenToMyBoy"></ConponentA> </div></template><script>import ConponentA from './components/componentA.vue'export default { data: function () { return { childWorlds: '' } }, components: {ConponentA}, watch: { items: { handler: function (items) { Store.save(items) }, deep: true } }, methods: { //监听 listenToMyBoy: function (msg) { console.log(msg) this.childWorlds = msg } } }</script>
除了这个方法外,还有其他方法,详见Vue.js官网
自定义组件指定属性数据类型
export default { props: { slides: { type: Array, //数组 default: [] //默认值 } }, 在加载完毕执行某个方法 mounted () { this.loadxxx() }
@mouseover="xxxx" 鼠标进入(执行某个事件), @mouseout="xxxx" 鼠标移出(执行某个事件);
transiotions动画对left和right等无效,要想实现动画效果,只能用x轴了;
slot 插槽
this.abc = false 等同于 this['abc'] = false
父组件style不添加scoped,这样他的子组件可以共用他的样式,也就是说,可以把子组件的样式,写在父组件中.
<!-- Add "scoped" attribute to limit CSS to this component only --><style>......</style>
& 代表父元素
<!--css书写规范 可被继承的写在前面,不让继承的的写在后面--><style lang="stylus" rel="stylesheet/stylus"> #app .tab display: flex width: 100% height: 40px line-height: 40px .tab-item flex: 1 text-align: center /* & > a & 代表父元素 tab-item 子元素选择器 */ & > a display: block font-style: 14px color: rgb(77,85,93) &.active color: rgb(240,20,20)</style>
1像素边框的实现
在pc端可以通过下面的设置,来实现,
border-bottom: 1px solid rgba(7,17,27,0.1)
相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
推荐阅读:
深入JavaScript之JS的运动
深入JavaScript之DOM的高级应用
深入JavaScript之小知识点
以上就是使用Vue.js有哪些注意事项的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的使用Vue.js有哪些注意事项全部内容,希望文章能够帮你解决使用Vue.js有哪些注意事项所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。