053_Result结果

本文详细介绍了如何在Vue项目中使用Element UI的Result组件创建成功、警告、信息和错误提示,并展示了如何通过 Slots 功能实现自定义图标和内容。从基础用法到自定义案例,适合前端开发者学习和实践。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Result结果

1.1. Result结果用于对用户的操作结果或者异常状态做反馈。

1.2. Result Attributes

参数

说明

类型

可选值

默认值

title

标题

string

sub-title

二级标题

string

icon

图标类型

string

success / warning / info / error

info

1.3.Result Slots

name

说明

icon

自定义图标

title

自定义标题

subTitle

自定义二级标题

extra

自定义底部额外区域

2. Result结果例子

2.1. 使用脚手架新建一个名为element-ui-result折叠面板的前端项目, 同时安装Element插件。

2.2. 编辑index.js 

import Vue from 'vue'
import VueRouter from 'vue-router'
import Result from '../components/Result.vue'
import SlotsResult from '../components/SlotsResult.vue'

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/Result' },
  { path: '/Result', component: Result },
  { path: '/SlotsResult', component: SlotsResult }
]

const router = new VueRouter({
  routes
})

export default router

2.3. 在components下创建Result.vue

<template>
  <div>
    <h1>基础用法</h1>
    <el-row>
      <el-col :span="6">
        <el-result icon="success" title="成功提示" subTitle="请根据提示进行操作"></el-result>
      </el-col>
      <el-col :span="6">
        <el-result icon="warning" title="警告提示" subTitle="请根据提示进行操作"></el-result>
      </el-col>
      <el-col :span="6">
        <el-result icon="error" title="错误提示" subTitle="请根据提示进行操作"></el-result>
      </el-col>
      <el-col :span="6">
        <el-result icon="info" title="信息提示" subTitle="请根据提示进行操作"></el-result>
      </el-col>
    </el-row>
  </div>
</template>

2.4. 在components下创建SlotsResult.vue

<template>
  <div>
    <h1>自定义内容</h1>
    <el-result title="404" subTitle="抱歉, 请求错误">
      <template slot="icon">
        <el-image src="https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png"></el-image>
      </template>
      <template slot="extra">
        <el-button type="primary" size="medium">返回</el-button>
      </template>
    </el-result>
  </div>
</template>

2.5. 运行项目, 访问http://localhost:8080/#/Result

2.6. 运行项目, 访问http://localhost:8080/#/SlotsResult 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值