html5项目改造Vue工程化

将html5项目改造成vue项目

也就是view层的vue文件:Index.vue

<template>i
 <div>
     将html代码粘贴到这里
 </div>
</template>
<script>
export default {
   name: 'Index',//注意这里就是Index.vue文件的名称
   data() {
          return {

          }
        },
        methods: {
            gotoTest(id) {
                // this.$router.push() 表示路由调转
                this.$router.push(`/test/${id}`)
            }
        },
        mounted() {
        },
  components: {
  }
}
</script>
<style lang="scss" scoped>
	@import "../assets/css/amazeui.css";
	@import "../assets/css/admin.css";
	@import "../assets/css/demo.css";
	@import "../assets/css/seastyle.css";
</style>

router层:
index.js
1.导入对应的包

import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/Index'
import Test from '../views/Test'
import Search from '../views/Search'
import Introduction from '../views/Introduction'

2.使用路由

Vue.use(VueRouter)

3.页面的跳转与参数的传递

const router = new VueRouter({
    mode: 'history',
    routes: [
        {
            path: '/',
            component: Index
        },
        {
            path: '/test/:abc',  // /test/45   /test/abc
            props: true,
            component: Test
        },
        {
            path: '/search',
            component: Search
        },
        {
            path: '/intr',
            component: Introduction
        }
    ]
})

4.导出路由

export default router

实例:

<template>
  <h1>Helle world, {{abc}}</h1>
</template>

<script>
export default {
  props: {
  //abc对应上面的 path: '/test/:abc',其实就是传递参数而已
    abc: Number  // String  地位上和data中的属性是一样的,在任何地方都可以使用 this.abc
  },
  data() {
    return {
      name: ''
    }
  },
  name: "Test"
}
</script>

<style scoped>

</style>
  • 5
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值