Vue相关资料

vue实现分页     Vue实例的生命周期created和mounted的区别     Vue.js 做表单验证   npm 安装包的路径在哪里

vue.js在visual studio 2017下的安装    MVC+Vue.js实现联系人管理    JSON.parse 和 JSON.stringify 详解

Vue在MVC中的进行前后端的交互   Vue基础系列(一)——Vue入坑第一篇

axios中文文档|axios中文网      vue中如何防止多次点击(防止重复提交)

vue 选城市三级联动     Vue.js 在 ASP.NET MVC 部分视图中如何使用 Vue 组件 (*.vue)

 

复制代码

<div id="example">
    <select v-model="prov">
        <option v-for="option in arr" :value="option.name">
            {{ option.name }}
        </option>
    </select>
    <select v-model="city">
        <option v-for="option in cityArr" :value="option.name">
            {{ option.name }}
        </option>
    </select>
    <select v-model="district" v-if="district">
        <option v-for="option in districtArr" :value="option.name">
            {{ option.name }}
        </option>
    </select>
</div>

<script type="text/javascript">
    var vm = new Vue({
        el: '#example',
        data: {
            arr: arrAll,
            prov: '北京',
            city: '北京',
            district: '东城区',
            cityArr: [],
            districtArr: []
        },
        methods: {
            updateCity: function () {
                for (var i in this.arr) {
                    var obj = this.arr[i];
                    if (obj.name == this.prov) {
                        this.cityArr = obj.sub;
                        break;
                    }
                }
                this.city = this.cityArr[1].name;
            },
            updateDistrict: function () {
                for (var i in this.cityArr) {
                    var obj = this.cityArr[i];
                    if (obj.name == this.city) {
                        this.districtArr = obj.sub;
                        break;
                    }
                }
                if(this.districtArr && this.districtArr.length > 0 && this.districtArr[1].name) {
                    this.district = this.districtArr[1].name;
                } else {
                    this.district = '';
                }
            }
        },
        beforeMount: function () {
            this.updateCity();
            this.updateDistrict();
        },
        watch: {
            prov: function () {
                this.updateCity();
                this.updateDistrict();
            },
            city: function () {
                this.updateDistrict();
            }
        }
    })
</script>

Vue的watch监听事件

posted on   大西瓜3721  阅读(158)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)

导航

点击右上角即可分享
微信分享提示