VueApi-06

Vue.js - day6

注意:

有时候使用npm i node-sass -D装不上,这时候,就必须使用 cnpm i node-sass -D

在普通页面中使用render函数渲染组件

在webpack中配置.vue组件页面的解析

  1. 运行cnpm i vue -S将vue安装为运行依赖;

  2. 运行cnpm i vue-loader vue-template-compiler -D将解析转换vue的包安装为开发依赖;

  3. 运行cnpm i style-loader css-loader -D将解析转换CSS的包安装为开发依赖,因为.vue文件中会写CSS样式;

  4. webpack.config.js中,添加如下module规则:


module: {

    rules: [

      { test: /\.css$/, use: ['style-loader', 'css-loader'] },

      { test: /\.vue$/, use: 'vue-loader' }

    ]

  }
  1. 创建App.js组件页面:

    <template>

      <!-- 注意:在 .vue 的组件中,template 中必须有且只有唯一的根元素进行包裹,一般都用 div 当作唯一的根元素 -->

      <div>

        <h1>这是APP组件 - {{msg}}</h1>

        <h3>我是h3</h3>

      </div>

    </template>



    <script>

    // 注意:在 .vue 的组件中,通过 script 标签来定义组件的行为,需要使用 ES6 中提供的 export default 方式,导出一个vue实例对象

    export default {

      data() {

        return {

          msg: 'OK'

        }

      }

    }

    </script>



    <style scoped>

    h1 {

      color: red;

    }

    </style>
  1. 创建main.js入口文件:

    // 导入 Vue 组件

    import Vue from 'vue'



    // 导入 App组件

    import App from './components/App.vue'



    // 创建一个 Vue 实例,使用 render 函数,渲染指定的组件

    var vm = new Vue({

      el: '#app',

      render: c => c(App)

    });

在使用webpack构建的Vue项目中使用模板对象?

  1. webpack.config.js中添加resolve属性:
resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    }
  }

ES6中语法使用总结

  1. 使用 export defaultexport 导出模块中的成员; 对应ES5中的 module.exportsexport

  2. 使用 import ** from **import '路径' 还有 import {a, b} from '模块标识' 导入其他模块

  3. 使用箭头函数:(a, b)=> { return a-b; }

在vue组件页面中,集成vue-router路由模块

vue-router官网

  1. 导入路由模块:

import VueRouter from 'vue-router'
  1. 安装路由模块:

Vue.use(VueRouter);
  1. 导入需要展示的组件:

import login from './components/account/login.vue'

import register from './components/account/register.vue'
  1. 创建路由对象:

var router = new VueRouter({

  routes: [

    { path: '/', redirect: '/login' },

    { path: '/login', component: login },

    { path: '/register', component: register }

  ]

});
  1. 将路由对象,挂载到 Vue 实例上:

var vm = new Vue({

  el: '#app',

  // render: c => { return c(App) }

  render(c) {

    return c(App);

  },

  router // 将路由对象,挂载到 Vue 实例上

});
  1. 改造App.vue组件,在 template 中,添加router-linkrouter-view

    <router-link to="/login">登录</router-link>

    <router-link to="/register">注册</router-link>



    <router-view></router-view>

组件中的css作用域问题

抽离路由为单独的模块

使用 饿了么的 MintUI 组件

Github 仓储地址

Mint-UI官方文档

  1. 导入所有MintUI组件:

import MintUI from 'mint-ui'
  1. 导入样式表:

import 'mint-ui/lib/style.css'
  1. 在 vue 中使用 MintUI中的Button按钮和Toast弹框提示:

Vue.use(MintUI)
  1. 使用的例子:

<mt-button type="primary" size="large">primary</mt-button>

Mint-UI中按需导入的配置方式

使用 MUI 代码片段

注意: MUI 不同于 Mint-UI,MUI只是开发出来的一套好用的代码片段,里面提供了配套的样式、配套的HTML代码段,类似于 Bootstrap; 而 Mint-UI,是真正的组件库,是使用 Vue 技术封装出来的 成套的组件,可以无缝的和 VUE项目进行集成开发;
因此,从体验上来说, Mint-UI体验更好,因为这是别人帮我们开发好的现成的Vue组件;
从体验上来说, MUI和Bootstrap类似;
理论上,任何项目都可以使用 MUI 或 Bootstrap,但是,MInt-UI只适用于Vue项目;

注意: MUI 并不能使用 npm 去下载,需要自己手动从 github 上,下载现成的包,自己解压出来,然后手动拷贝到项目中使用;

官网首页

文档地址

  1. 导入 MUI 的样式表:

import '../lib/mui/css/mui.min.css'
  1. webpack.config.js中添加新的loader规则:

{ test: /\.(png|jpg|gif|ttf)$/, use: 'url-loader' }
  1. 根据官方提供的文档和example,尝试使用相关的组件

将项目源码托管到oschina中

  1. 点击头像 -> 修改资料 -> SSH公钥 如何生成SSH公钥

  2. 创建自己的空仓储,使用 git config --global user.name "用户名"git config --global user.email ***@**.com 来全局配置提交时用户的名称和邮箱

  3. 使用 git init 在本地初始化项目

  4. 使用 touch README.mdtouch .gitignore 来创建项目的说明文件和忽略文件;

  5. 使用 git add . 将所有文件托管到 git 中

  6. 使用 git commit -m "init project" 将项目进行本地提交

  7. 使用 git remote add origin 仓储地址将本地项目和远程仓储连接,并使用origin最为远程仓储的别名

  8. 使用 git push -u origin master 将本地代码push到仓储中

App.vue 组件的基本设置

  1. 头部的固定导航栏使用 Mint-UIHeader 组件;

  2. 底部的页签使用 muitabbar;

  3. 购物车的图标,使用 icons-extra 中的 mui-icon-extra mui-icon-extra-cart,同时,应该把其依赖的字体图标文件 mui-icons-extra.ttf,复制到 fonts 目录下!

  4. 将底部的页签,改造成 router-link 来实现单页面的切换;

  5. Tab Bar 路由激活时候设置高亮的两种方式:

    • 全局设置样式如下:
    
    .router-link-active{
    
        color:#007aff !important;
    
    }
    
    • 或者在 new VueRouter 的时候,通过 linkActiveClass 来指定高亮的类:
    
    // 创建路由对象
    
    var router = new VueRouter({
    
      routes: [
    
        { path: '/', redirect: '/home' }
    
      ],
    
      linkActiveClass: 'mui-active'
    
    });
    

实现 tabbar 页签不同组件页面的切换

  1. 将 tabbar 改造成 router-link 形式,并指定每个连接的 to 属性;

  2. 在入口文件中导入需要展示的组件,并创建路由对象:


    // 导入需要展示的组件

    import Home from './components/home/home.vue'

    import Member from './components/member/member.vue'

    import Shopcar from './components/shopcar/shopcar.vue'

    import Search from './components/search/search.vue'



    // 创建路由对象

    var router = new VueRouter({

      routes: [

        { path: '/', redirect: '/home' },

        { path: '/home', component: Home },

        { path: '/member', component: Member },

        { path: '/shopcar', component: Shopcar },

        { path: '/search', component: Search }

      ],

      linkActiveClass: 'mui-active'

    });

使用 mt-swipe 轮播图组件

  1. 假数据:

lunbo: [

        'http://www.itcast.cn/images/slidead/BEIJING/2017440109442800.jpg',

        'http://www.itcast.cn/images/slidead/BEIJING/2017511009514700.jpg',

        'http://www.itcast.cn/images/slidead/BEIJING/2017421414422600.jpg'

      ]
  1. 引入轮播图组件:

<!-- Mint-UI 轮播图组件 -->

    <div class="home-swipe">

      <mt-swipe :auto="4000">

        <mt-swipe-item v-for="(item, i) in lunbo" :key="i">

          <img :src="item" alt="">

        </mt-swipe-item>

      </mt-swipe>

    </div>

  </div>

.vue组件中使用vue-resource获取数据

  1. 运行cnpm i vue-resource -S安装模块

  2. 导入 vue-resource 组件


import VueResource from 'vue-resource'
  1. 在vue中使用 vue-resource 组件

Vue.use(VueResource);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,可以看出用户发送了一个POST请求到URL为http://localhost:9528/dev-api/vue-admin-template/user/login,并且发送的json数据为{ "username": "admin", "password": "111111" }。返回的数据为{ "code": 20000, "data": { "token": "admin-token" } }。\[1\] 然后用户发送了一个GET请求到URL为http://localhost:9528/dev-api/vue-admin-template/user/info?token=admin-token,并且发送的数据为admin-token。返回的数据为{ "code": 20000, "data": { "roles": \["admin"\], "introduction": "I am a super administrator", "avatar": "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif", "name": "Super Admin" } }。\[2\] 根据提供的代码,可以看出用户在src/api/user.js文件中修改了对应的访问地址,其中login函数发送了一个POST请求到URL为/admin/vod/user/login,getInfo函数发送了一个GET请求到URL为/admin/vod/user/info,logout函数发送了一个POST请求到URL为/admin/vod/user/logout。\[3\] 根据提供的信息,问题中的URL为http://localhost:9527/dev-api/vue-element-admin/user/login,返回了404 (Not Found)错误。根据提供的引用内容,我们无法得知为什么会返回404错误,可能是URL地址不正确或者该接口不存在。建议检查URL地址是否正确,并确保该接口存在。 #### 引用[.reference_title] - *1* *2* *3* [直播课堂系统06-搭建项目前端环境](https://blog.csdn.net/z754916067/article/details/125976873)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值