利用vue实现级联菜单


<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Documenttitle>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">script>
head>
<body>
    <div id="app">
        省份:
        <select v-model='i'>
            <option v-for='(prov,index) of provs' :key='index' :value='index' v-text='prov'>option>
        select>
        城市:
        <select v-model='j'>
            <option v-for='(city,index) of cities[i]' :key='index' :value='index' v-text='city'>option>
        select>
    div>
    <script>
        new Vue({
            el:'#app',
            data:{
                i:0,
                j:0,
                provs:['北京','河北','山东'],
                cities:[
                    ['东城','西城','海淀','朝阳'],
                    ['石家庄','保定','唐山','廊坊'],
                    ['济南','青岛','烟台','德州']
                ]
            },
            watch:{
                i(){ this.j=0 }
            }
        })
    script>
body>
html>

你可能感兴趣的:(前端,vue)