vue.js 2.0 版本—组件化demo

1.拆分组件

将页面拆分成:头部区域,导航区域,内容区域

2.创建目录

vue项目src/component目录下创建:
├── header                         //头部区域文件夹
│    ├──header.vue               
├── content                         //内容区域文件夹
│    ├──content.vue               
├── tab                         //导航区域文件夹
│    ├──tab.vue

3.头部区域,导航区域,内容区域的代码编写

  • 编写header.vue文件内容如下
<template>
  <div class="header">
    this is header
  </div>
</template>
<script type="text/ecmascript-6">
export default {
  name: 'header',
  data () {
    return {
      msg: 'Welcome to this is header'
    }
  }
}
</script>
<style lang="stylus" rel="stylesheet/stylus">

</style>
  • 编写cotent.vue文件内容如下
<template>
  <div class="content">
    this is content
  </div>
</template>
<script type="text/ecmascript-6">
export default {
  name: 'content',
  data () {
    return {
      msg: 'Welcome to this is content'
    }
  }
}
</script>
<style lang="stylus" rel="stylesheet/stylus">
</style>
  • 编写cotent.vue文件内容如下
<template>
  <div class="tab">
    this is tab
  </div>
</template>
<script type="text/ecmascript-6">
export default {
  name: 'tab',
  data () {
    return {
      msg: 'Welcome to this is tab'
    }
  }
}
</script>
<style lang="stylus" rel="stylesheet/stylus">
</style>

4.app.vue代码的编写

<template>
  <div id="app">
    <app-header></app-header>
    <app-content></app-content>
    <app-tab></app-tab>
  </div>
</template>

<script>
import AppHeader from '@/components/header/header'
import AppContent from '@/components/content/content'
import AppTab from '@/components/tab/tab'

export default {
  name: 'App',
  components: {
    AppHeader,
    AppContent,
    AppTab
  }

}
</script>

<style>
</style>

5.运行结果

this is header
this is content
this is tab

6.创建vue模板

File - Settings - File and Code Templates 右侧的+添加vue file文件,在内容里面添加

<template>
</template>
<script type="text/ecmascript-6">
</script>
<style lang="stylus" rel="stylesheet/stylus">
</style>

7.vue报错处理

7.1 报错及解决方案
  1. 在运行vue 报错误:

    This dependency was not found
  2. 解决方案:

    npm install stylus-loader css-loader style-loader --save-dev

7.1参考地址

7.2 报错及解决方案
  1. 在运行vue 报错误:

    Cannot find modulestylus
  2. 解决方案:

    npm install stylus  --save-dev

7.2参考地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值