如何使用Link,Radio,Checkbox,Select,Cascader组件

发布时间:2021-10-11 18:16:18 作者:iii
来源:亿速云 阅读:126

这篇文章主要介绍“如何使用Link,Radio,Checkbox,Select,Cascader组件”,在日常操作中,相信很多人在如何使用Link,Radio,Checkbox,Select,Cascader组件问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何使用Link,Radio,Checkbox,Select,Cascader组件”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

1.Link组件动态绑定URL

<div id="home" >
    <el-row :gutter="40">
        <el-col :span="16">
            <el-form label-width="100px">
                <el-link :href="href" target="_blank">默认链接</el-link>
            </el-form>
        </el-col>
    </el-row>
</div>

对应的js代码

<script type="text/javascript">
    new Vue({
        el: '#home',
        data: {
            href: ''
        },
        mounted() {
            this.init()
        },
        methods: {
            init() {
                this.href = "https://www.baidu.com/"
            }
        }
    })
</script>

2.Radio 用法

<el-radio-group v-model="addType" @change="radioChange">
    <el-radio :label="1" >备选项1</el-radio>
    <el-radio :label="2" >备选项2</el-radio>
    <el-radio :label="3" >备选项3</el-radio>
</el-radio-group>

对应的js代码

<script type="text/javascript">
    new Vue({
        el: '#home',
        data: {
            addType: null       # 必须声明绑定的值,否则页面无法渲染
        },
        mounted() {
            this.init()
        },
        methods: {
            init() {

            },
            radioChange() {
                console.log(this.addType)
            }
        }
    })
</script>

当选项被选中时,会调用radioChange方法。

3.Checkbox用法

方式一:

<el-input-number v-model="num" @change="handleChange" :min="1" :max="10" label="描述文字"></el-input-number>

对应的js代码

<script type="text/javascript">
    new Vue({
        el: '#home',
        data: {
            num: ''
        },
        mounted() {
            this.init()
        },
        methods: {
            init() {

            },
            checkChange() {
                console.log(this.num)
            }
        }
    })
</script>

当标签中的值改变时,会调用handleChange方法。

方式二:

<el-input-number v-model="num" :min="1" :max="10" label="描述文字"></el-input-number>
<el-button type="success" @click="getSearch">搜索</el-button>

对应的js代码

<script type="text/javascript">
    new Vue({
        el: '#home',
        data: {
            num: '',
        },
        mounted() {
            this.init()
        },
        methods: {
            init() {

            },
            getSearch() {
                console.log(this.num)
            }
        }
    })
</script>

当搜索按钮被点击时,会触发getSearch方法,获取到num的值。

4.Select 用法

方式一:

el-option中只需要声明keyvalue的值即可

<el-select v-model="value" placeholder="请选择">
    <el-option v-for="item in options" :key="item.value" :value="item.value"></el-option>
</el-select>
<el-button type="success" @click="getSearch">搜索</el-button>

对应的js代码

<script type="text/javascript">
    new Vue({
        el: '#home',
        data: {
            options: [],
            value: ''
        },
        mounted() {
            this.init()
        },
        methods: {
            init() {
                this.options = [
                    {
                        value: '黄金糕',
                        label: '黄金糕'
                    }, {
                        value: '双皮奶',
                        label: '双皮奶'
                    }, {
                        value: '蚵仔煎',
                        label: '蚵仔煎'
                    }, {
                        value: '龙须面',
                        label: '龙须面'
                    }, {
                        value: '北京烤鸭',
                        label: '北京烤鸭'
                    }
                ]
            },
            getSearch() {
                console.log(this.value)
            }
        }
    })
</script>

可以先声明options为空数组,然后在init方法中为options数组赋值(可以异步请求后端数据,将后端响应数据赋值)

当搜索按钮被点击时,会触发getSearch方法,获取到el-select被选中的值。

方式二:

<el-select v-model="value" placeholder="请选择" @change="selectChange">
    <el-option v-for="item in options" :key="item.value" :value="item.value"></el-option>
</el-select>

对应的js代码

<script type="text/javascript">
    new Vue({
        el: '#home',
        data: {
            options: [],
            value: ''
        },
        mounted() {
            this.init()
        },
        methods: {
            init() {
                this.options = [
                    {
                        value: '黄金糕',
                        label: '黄金糕'
                    }, {
                        value: '双皮奶',
                        label: '双皮奶'
                    }, {
                        value: '蚵仔煎',
                        label: '蚵仔煎'
                    }, {
                        value: '龙须面',
                        label: '龙须面'
                    }, {
                        value: '北京烤鸭',
                        label: '北京烤鸭'
                    }
                ]
            },
            selectChange() {
                console.log(this.value)
            }
        }
    })
</script>

select选项改变时,会调用selectChange方法。

如需要在下拉菜单中选中多个值中,可以在el-select标签中加入multiple选项,多选中标签的结果是一个数组。

<el-select v-model="value" multiple placeholder="请选择" @change="selectChange">
    <el-option v-for="item in options" :key="item.value" :value="item.value"></el-option>
</el-select>

7.Cascader 级联菜单组件用法

<el-cascader v-model="value" :options="options" @change="handleChange" ></el-cascader>

对应的js代码

<script type="text/javascript">
    new Vue({
        el: '#home',
        data: {
            options: [],
            value: ''
        },
        mounted() {
            this.init()
        },
        methods: {
            init() {
                this.options = [
                    {
                        value: 'zhinan', label: '指南',
                        children: [
                            {
                                value: 'shejiyuanze', label: '设计原则',
                                children: [
                                    {value: 'yizhi', label: '一致'},
                                    {value: 'fankui', label: '反馈'},
                                    {value: 'xiaolv', label: '效率'},
                                    {value: 'kekong', label: '可控'}
                                ]
                            }, {
                                value: 'daohang', label: '导航',
                                children: [
                                    {value: 'cexiangdaohang', label: '侧向导航'},
                                    {value: 'dingbudaohang', label: '顶部导航'}
                                ]
                            }
                        ]
                    }, {
                        value: 'zujian', label: '组件',
                        children: [
                            {
                                value: 'basic', label: 'Basic',
                                children: [
                                    {value: 'layout', label: 'Layout 布局'},
                                    {value: 'color', label: 'Color 色彩'},
                                    {value: 'typography', label: 'Typography 字体'},
                                    {value: 'icon', label: 'Icon 图标'},
                                    {value: 'button', label: 'Button 按钮'}
                                ]
                            }, {
                                value: 'form', label: 'Form',
                                children: [
                                    {value: 'radio', label: 'Radio 单选框'},
                                    {value: 'checkbox', label: 'Checkbox 多选框'},
                                    {value: 'input', label: 'Input 输入框'},
                                    {value: 'input-number', label: 'InputNumber 计数器'},
                                    {value: 'select', label: 'Select 选择器'},
                                    {value: 'cascader', label: 'Cascader 级联选择器'},
                                    {value: 'switch', label: 'Switch 开关'},
                                    {value: 'slider', label: 'Slider 滑块'},
                                    {value: 'time-picker', label: 'TimePicker 时间选择器'},
                                    {value: 'date-picker', label: 'DatePicker 日期选择器'},
                                    {value: 'datetime-picker', label: 'DateTimePicker 日期时间选择器'},
                                    {value: 'upload', label: 'Upload 上传'},
                                    {value: 'rate', label: 'Rate 评分'},
                                    {value: 'form', label: 'Form 表单'}
                                ]
                            }, {
                                value: 'data', label: 'Data',
                                children: [
                                    {value: 'table', label: 'Table 表格'},
                                    {value: 'tag', label: 'Tag 标签'},
                                    {value: 'progress', label: 'Progress 进度条'},
                                    {value: 'tree', label: 'Tree 树形控件'},
                                    {value: 'pagination', label: 'Pagination 分页'},
                                    {value: 'badge', label: 'Badge 标记'}
                                ]
                            }, {
                                value: 'notice', label: 'Notice',
                                children: [
                                    {value: 'alert', label: 'Alert 警告'},
                                    {value: 'loading', label: 'Loading 加载'},
                                    {value: 'message', label: 'Message 消息提示'},
                                    {value: 'message-box', label: 'MessageBox 弹框'},
                                    {value: 'notification', label: 'Notification 通知'}
                                ]
                            }, {
                                value: 'navigation', label: 'Navigation',
                                children: [
                                    {value: 'menu', label: 'NavMenu 导航菜单'},
                                    {value: 'tabs', label: 'Tabs 标签页'},
                                    {value: 'breadcrumb', label: 'Breadcrumb 面包屑'},
                                    {value: 'dropdown', label: 'Dropdown 下拉菜单'},
                                    {value: 'steps', label: 'Steps 步骤条'}
                                ]
                            }, {
                                value: 'others', label: 'Others',
                                children: [
                                    {value: 'dialog', label: 'Dialog 对话框'},
                                    {value: 'tooltip', label: 'Tooltip 文字提示'},
                                    {value: 'popover', label: 'Popover 弹出框'},
                                    {value: 'card', label: 'Card 卡片'},
                                    {value: 'carousel', label: 'Carousel 走马灯'},
                                    {value: 'collapse', label: 'Collapse 折叠面板'}
                                ]
                            }
                        ]
                    },
                    {
                        value: 'ziyuan', label: '资源',
                        children: [
                            {value: 'axure', label: 'Axure Components'},
                            {value: 'sketch', label: 'Sketch Templates'},
                            {value: 'jiaohu', label: '组件交互文档'}
                        ]
                    }
                ]
            },
            getSearch() {
                console.log(this.value)
            }
        }
    })
</script>

可以先声明options为空数组,然后在init方法中为options数组赋值(可以异步请求后端数据,将后端响应数据赋值)

需要选中值就触发方法时,可以加@change="handleChange"选项来绑定触发方法

需指定长度时,可以加选项

其选中结果为一个数组类型,可以直接加索引获取选中的值

到此,关于“如何使用Link,Radio,Checkbox,Select,Cascader组件”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. jQuery如何操作radio、checkbox、select
  2. Jquery操作radio,checkbox,select表单操作实现代码

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

link radio checkbox

上一篇:爬虫代理怎样去选择

下一篇:Python如何求中心索引

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》