vue框架的简单使用

项目总览

在这里插入图片描述

index.js

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Panda from '@/components/panda'
import Spotslist from '@/components/spotslist'
import Hotellist from '@/components/hotellist'
import Spots from '@/components/spots'
import Hotel from '@/components/hotel'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: '首页',
      component: Panda
    },
    {
      path: '/HelloWorld',
      name: '测试页面',
      component: HelloWorld
    },
    {
      path: '/spotslist',
      name: '景点详情',
      component: Spotslist
    },
    {
      path: '/hotellist/:id',
      name: '酒店详情',
      component: Hotellist
    },
    {
      path: '/spots',
      name: '景点详情',
      component: Spots
    },
    {
      path: '/hotel',
      name: '酒店详情',
      component: Hotel
    }
  ]
})

validate.js

// 判断是否为空
export const isDataValid = (data) => {
  if (data != null && data !== '' && data !== 'undefined' && data !== null && data != undefined) {
    return true
  }
  return false
  }
export const config = {
  dataserver: 'http://127.0.0.1:8081/',
  imgserver: 'http://192.168.1.100/'
}


panda.vue

一:使用数据

script>
import {isDataValid,config} from '../util/validate'
import {service} from '../util/service'
import axios from 'axios'

export default {
  name: 'panda',   //是哪个页面
  data () {   //页面需要使用的数据
    return {
    inputValue: '',
      username: '张三',
      password: '123',
       arealist:  [{areaid: '', areaname: '', areastate: '', areasort: ''} ],
      spotlist:  [{spotsid: '',spotname: '',spotsaddr: '',spotsaddr2: '',spotsopentime: '',
        spotsoneworlds: '',spotsimg: '',spotsstate: '',spotsfirst: '',spotshot: '',
        spotsareaid: '',spotsareaname: '',spotsdesc: ''}],   //这个写出来只是方便阅读
      typelist: [{htid: '',htname: '',htstate: '',htsort: ''}],
      hotellist: [{}],  //直接这样子写就可以了
      imgserver: config.imgserver
    }
  },

二:调用方法(可连接数据接口)

 methods: {   //方法
 getIndex (index) {
      // console.log(index)
      this.curIndex = index
    },
    product (areaid) {
      let that = this
      axios.get(config.dataserver + 'spots/getdatabyid?id=' + areaid).then(res => {
        that.spotlist = res.data
      })
    },
    products(){
      let that=this
      axios.get(config.dataserver + 'spots/getdata').then(res =>{
        that.spotlist=res.data
      })
    },

三:(数据接口)

mounted: function () {   //数据接口
    let that = this
    axios.get(config.dataserver + 'sys/area/getdata').then(res =>{
      that.arealist = res.data
      console.log(res.data)  //显示得到的数据
    })

    axios.get(config.dataserver + 'spots/getdata').then(res =>{
      that.spotlist = res.data
      console.log(res.data)
    })

四:使用数据

  <li v-for="item in arealist"  @click="product(item.areaid)">
                    {{item.areaname}}
                  </li>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值