1 <template>
2 <view class="container">
3 <view class="title">
4 <text>uni-data-picker 本地数据</text>
5 </view>
6 <uni-data-picker placeholder="请选择班级" popup-title="请选择所在地区" :localdata="dataTree" v-model="classes"
7 @nodeclick="onnodeclick" @popupclosed="onpopupclosed">
8 </uni-data-picker>
9
10 </view>
11 </template>
12
13 <script>
14 export default {
15 data() {
16 return {
17 tempClasses : '', // 临时存放vue值
18 classes: '1-2',
19 dataTree: [{
20 text: "一年级",
21 value: "1-0",
22 children: [{
23 text: "1.1班",
24 value: "1-1"
25 },
26 {
27 text: "1.2班",
28 value: "1-2"
29 }]
30 },
31 {
32 text: "二年级",
33 value: "2-0",
34 children: [{
35 text: "2.1班",
36 value: "2-1"
37 },
38 {
39 text: "2.2班",
40 value: "2-2"
41 }]
42 },
43 {
44 text: "三年级",
45 value: "3-0",
46 disable: true
47 }]
48 }
49 },
50 methods: {
51 /** 点击选项时执行方法
52 * @param {Object} e
53 */
54 onnodeclick(e) {
55 this.tempClasses = e.value;
56 },
57 /** 关闭弹出框执行方法
58 * @param {Object} e
59 */
60 onpopupclosed(e) {
61 this.classes = this.tempClasses;
62 },
63 }
64 }
65 </script>
66
67 <style>
68 .container {
69 height: 100%;
70 /* #ifndef APP-NVUE */
71 display: flex;
72 max-width: 500px;
73 padding: 0 15px;
74 /* #endif */
75 flex-direction: column;
76 }
77
78 .title {
79 font-size: 14px;
80 font-weight: bold;
81 margin: 20px 0 5px 0;
82 }
83
84 .data-pickerview {
85 height: 400px;
86 border: 1px #e5e5e5 solid;
87 }
88 </style>