11、Vue之分页组件(勾选、过滤)、五级联动、两种多层弹窗组件、报错与解决、效果与实现之表单、表格节目单飞走聚焦、多行收缩展开动画、滚动条回到顶部与底部、任务队列执行栈、深度选择器、图片预览、拖拽之勾选表格列表、先选中的在前(3100行)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 | 一、vue之分页组件(含勾选、过滤) <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <title>勾选和分页组件之vue2.6.10版</title> <script src= "https://cdn.bootcss.com/vue/2.6.10/vue.min.js" ></script> <style> table{ border-collapse: collapse; border: 1px solid #cbcbcb; width: 1000px; } table td,table th { padding: 5px; border: 1px solid #cbcbcb; } table thead { background-color: #e0e0e0; color: #000; text-align: left; } .filter{ width:998px; border:1px solid gray; padding:10px 0px; } .line{ display:flex } . group { width:330px; } .label{ display: inline-block; width:120px; height: 24px; line-height: 24px; text-align: right; } .input{ display: inline-block; width:180px; height: 24px; line-height: 24px; border-radius: 3px; } . select { display: inline-block; width:188px; height: 26px; line-height: 26x; border-radius: 3px; } </style> </head> <body> <div id= "app" > <div style= "padding-bottom:5px;color:red" > <button style= "color:red" @click= "checkDatasOne.getResultOfCheckAndFilter(divideDatasOne.isShowFilter,divideDatasOne.filterOptions)" >获取勾选和过滤结果</button> <span>{{checkDatasOne.toServerDatas}}</span> </div> <div style= "padding-bottom:5px" > <img :src= "checkDatasOne.stateAllPages&&checkDatasOne.allExcludedIds.length===0?checkImg.yes:checkImg.no" @click= "checkDatasOne.clickAllPages(divideDatasOne.tableDatas)" /> <span>{{checkDatasOne.textAllPages}}</span> </div> <div style= "padding-bottom:5px" > <button @click= "divideDatasOne.toggleShowFilter()" >{{divideDatasOne.isShowFilter? '关闭过滤' : '使用过滤' }}</button> <button @click= "divideDatasOne.emptyFilterOptions({value5:10})" >清空过滤</button> <button @click= "divideDatasOne.request(1,divideDatasOne.eachPageItemsNum)" >刷新</button> </div> <div style= "margin-bottom:5px" class = "filter" v-show= "divideDatasOne.isShowFilter" > <div class = "line" > <div class = "group" > <label class = "label" >标签</label> <input class = "input" type= "text" v-model= "divideDatasOne.filterOptions.value1" /> </div> <div class = "group" > <label class = "label" >这就是长标签</label> <input class = "input" type= "text" v-model= "divideDatasOne.filterOptions.value2" /> </div> <div class = "group" > <label class = "label" >标签</label> <input class = "input" type= "text" v-model= "divideDatasOne.filterOptions.value3" /> </div> </div> <div class = "line" style= "padding-top: 10px;" > <div class = "group" > <label class = "label" >这就是长标签</label> <input class = "input" type= "text" v-model= "divideDatasOne.filterOptions.value4" /> </div> <div class = "group" > <label class = "label" >下拉框</label> < select class = "select" v-model= "divideDatasOne.filterOptions.value5" > <option v- for = "item in selectOptions" :value= "item.back" >{{item.front}}</option> </ select > </div> <div class = "group" > <label class = "label" ></label> <button style= "width:188px;height:28px" @click= "divideDatasOne.request(1,divideDatasOne.eachPageItemsNum)" >过滤</button> </div> </div> </div> <div style= "width: 1000px" > <table> <thead> <tr> <th><img :src= "checkDatasOne.stateThisPage?checkImg.yes:checkImg.no" @click= "checkDatasOne.clickThisPage(divideDatasOne.tableDatas,divideDatasOne.allItemsNum)" /></th> <th>序号</th> <th>数据1</th> <th>数据2</th> <th>数据3</th> <th>数据4</th> <th>数据5</th> <th>数据6</th> </tr> </thead> <tbody> <tr v- for = "(data,index) in divideDatasOne.tableDatas" > <td><img :src= "data.state?checkImg.yes:checkImg.no" @click= "checkDatasOne.clickSingleItem(data,divideDatasOne.tableDatas,divideDatasOne.allItemsNum)" /></td> <td>{{(divideDatasOne.nowPageNum-1)*divideDatasOne.eachPageItemsNum + (index+1)}} </td> <td>{{ data.key1 }}</td> <td>{{ data.key2 }}</td> <td>{{ data.key3 }}</td> <td>{{ data.key4 }}</td> <td>{{ data.key5 }}</td> <td>{{ data.key6 }}</td> </tr> </tbody> </table> </div> <divide-page :divide-datas= "divideDatasOne" :check-datas= "checkDatasOne" : fixed -datas= "fixedDatas" ></divide-page> </div> </body> <script> new Vue({ el: '#app' , data(){ return { divideDatasOne:{ nowPageNum:0, allPagesNum:0, allItemsNum:0, eachPageItemsNum:0, tableDatas:[], filterOptions:{value5:10}, isShowFilter: false , otherDatas:{} }, checkDatasOne:{ idKey: 'id' , //每条数据的唯一标志 stateThisPage: false , //当前页所有项是否全选 allIncludedIds: [], //所有被选中数据的ID构成的数组 allExcludedIds: [], //所有没被选中数据的ID构成的数组 textAllPages: '全选未启用,没有选择任何项!' , //复选框被点击后的提示文字。 stateAllPages: false , //复选框被点击后的提示文字。 toServerDatas: null , }, } }, methods: { }, created(){ this .fixedDatas = {}; this .selectOptions = [ { back: 10, front: '来' }, { back: 20, front: '来自于' }, { back: 30, front: '来自于国内' }, { back: 40, front: '来自于国内攻击' }, { back: 50, front: '来自于国内攻击-2' } ]; this .checkImg = { yes: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAADqADAAQAAAABAAAADgAAAAC98Dn6AAAA+UlEQVQoFZWSMU4DMRBF/584G7QSRcIxuAZKEykNEiUVHVTQRaKh4AIcgAvQpkukVDlBOAYNSGSlXXuwpViyYYFdS9aMZ/6bsezh5HZ3T2KhqkfosEhWqnjkyd1u3xWKdQMsfaEAB0Zilf8swfdU0w0klmpGpz1BvpbHcklbPf8Okts0CfJtWBTz/Yc++Jc8S3PZVQfKGwiuvMD6XYsMzm1dT/1jXKdQ8E0asHRrAzOzbC6UGINWHPQp1UQ/6wjF2LpmJSKfhti4Bi8+lhWP4I+gAqV1uqSi8j9WRuF3m3eMWVUJBeKxzUoYn7bEX7HDyPmB7QEHbRjyL+/+VnuXDUFOAAAAAElFTkSuQmCC' , no: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAADqADAAQAAAABAAAADgAAAAC98Dn6AAAAbklEQVQoFWM8c+ZMLQMDQxUQcwAxMeAHUFEbC5CoYmNj02ZmZn5FjK6/f/+K/fr16ypIIwdIk7a29hdiNF69ehWkjIOJGMXY1IxqxBYqULEhFDiglPMDlIygKQKPryBSILUgPSCNbaC0B6RJSuQAbowizhJuOsAAAAAASUVORK5CYII=' , } }, components: { dividePage: { props: { divideDatas: { type: Object, default : {} }, checkDatas: { type: Object, default : {} }, fixedDatas: { type: Object, default : {} } }, template: ` <div v-show= "divideDatas.allPagesNum>=1" style= "display:flex;width:1000px;margin-top:20px;" > <div> <button v-show= "divideDatas.allPagesNum>10" @click= "clickDividePage('front') " :disabled= "divideDatas.nowPageNum===1" >上一页</button> <button :disabled= "number==='...'" v- for = "number in divideArray" @click= "clickDividePage(number)" :style= "{marginRight:'5px',color:number===divideDatas.nowPageNum?'red':'gray'}" >{{ number }}</button> <button v-show= "divideDatas.allPagesNum>10" @click= "clickDividePage('back')" :disabled= "divideDatas.nowPageNum===divideDatas.allPagesNum" >下一页</button> </div> <div style= "display:flex; flex:1; justify-content:flex-end;" > <div style= "margin-right:20px;" > <span>转到第</span> <input type= "text" v-model= "customString" @keydown= "clickDividePage('leap',$event)" style= "width:30px;" > <span>页</span> <button @click= "clickDividePage('leap',{which:13})" >Go</button> </div> <div> <span>每页显示</span> < select v-model= "divideDatas.eachPageItemsNum" @change= "selectChange(divideDatas.eachPageItemsNum)" > <option v- for = "item in numOptions" :value= "item.back" >{{item.front}}</option> </ select > <span>条,</span> </div> <div> <span>{{frontMoreText}}</span> <span>{{totalText}}</span> <span>{{divideDatas.allItemsNum}}</span> <span>{{totalUnit}}</span> <span>{{backMoreText}}</span> </div> </div> </div `, data() { return { customString: '' } }, created(){ var that = this ; //1、请求配置 this .url = this .fixedDatas.url || '' ; this .method = this .fixedDatas.method || 'post' ; this .isShowParams = this .fixedDatas.isShowParams || false ; //显式还是隐式传参。有时需要在请求发出前手动改变。 //2、响应配置(前端通过这个配置,获取后台的数据) this .nowPageNum = this .fixedDatas.nowPageNum || 'nowPageNum' ; //来自服务器的当前页码 this .allPagesNum = this .fixedDatas.allPagesNum || 'allPagesNum' ; //来自服务器的所有页页数 this .allItemsNum = this .fixedDatas.allItemsNum || 'allItemsNum' ; //来自服务器的所有页数据数 this .eachPageItemsNum = this .fixedDatas.eachPageItemsNum || 'eachPageItemsNum' ; //来自服务器的每页最多数据数 this .tableDatas = this .fixedDatas.tableDatas || 'tableDatas' ; //来自服务器的表格数据 //3、以下配置使用哪种转圈方式(前端根据需要决定,不受后台影响) this .partCircle = this .fixedDatas.partCircle; //局部是否转圈。this.fixedDatas.partCircle=$scope.partCircle={isShow =false}。 this .isUsePartCircle = this .fixedDatas.isUsePartCircle; //局部是否转圈,由当前页的一个变量控制 this .isUseWholeCircle = this .fixedDatas.isUseWholeCircle; //全局是否转圈,由本项目的一个服务控制 //4、初始化以下数据,供页面使用(前端根据需要决定,不受后台影响) this .frontMoreText = this .fixedDatas.frontMoreText || "" ; //('文字 ')或者("文字 "+result.numOne+" 文字 ") this .totalText = this .fixedDatas.totalText || "" ; //'共' this .totalUnit = this .fixedDatas.totalUnit || '条' ; //总数据的单位 this .backMoreText = this .fixedDatas.backMoreText || "" ; //(' 文字')或者("文字 "+result.numThree+" 文字") this .numOptions = [ { back: 10, front: 10 }, { back: 20, front: 20 }, { back: 30, front: 30 }, { back: 40, front: 40 }, { back: 50, front: 50 } ]; this .request = this .divideDatas.request = function (nowPageNum,eachPageItemsNum) { var isOnce = true ; //1、向后台发送请求, //2、返回正确结果result var data=[]; var allItemsNum = 193; var nowPageNum = nowPageNum||1; var eachPageItemsNum = eachPageItemsNum||10; var allPagesNum = Math.ceil(allItemsNum/eachPageItemsNum); for ( var i=1;i<=allItemsNum;i++){ var obj={ id: 'id' +i, key1: '数据' +(i+0), key2: '数据' +(i+1), key3: '数据' +(i+2), key4: '数据' +(i+3), key5: '数据' +(i+4), key6: '数据' +(i+5), key7: '数据' +(i+6), }; data.push(obj) } var tableDatas = data.slice((nowPageNum-1)*eachPageItemsNum,nowPageNum*eachPageItemsNum); //3、使用正确结果result that.customString = nowPageNum; that.divideDatas.nowPageNum = nowPageNum; that.divideDatas.allPagesNum = allPagesNum; that.divideDatas.allItemsNum = allItemsNum; that.divideDatas.eachPageItemsNum = eachPageItemsNum; that.divideDatas.tableDatas = tableDatas; //正常逻辑 if (that.divideDatas.once && isOnce){ //只使用一次,常用于初始化一些数据,比如过滤条件 that.divideDatas.once(); isOnce = false ; } if (that.divideDatas.trueCb){ //异常逻辑 that.divideDatas.trueCb() } if (that.checkDatas && that.checkDatas.signCheckbox){ //处理勾选 that.checkDatas.signCheckbox(that.divideDatas.tableDatas) } that.createDividePage(); //创建分页 //4、处理错误结果 if (that.divideDatas.errorCb){ that.divideDatas.errorCb() } }; if (! this .divideDatas.isAbandonInit) { this .request(1, this .divideDatas.eachPageItemsNum); }; this .divideDatas.toggleShowFilter = function () { this .isShowFilter = ! this .isShowFilter; if (! this .isShowFilter) { this .request(1,that.divideDatas.eachPageItemsNum); } }; this .divideDatas.emptyFilterOptions = function (extraObject) { //清空选项时,所有值恢复成默认 for ( var key in this .filterOptions){ this .filterOptions[key] = undefined; }; if (extraObject) { //小部分选项的默认值不是undefined for ( var key in extraObject){ this .filterOptions[key] = extraObject[key]; }; }; this .request(1,that.divideDatas.eachPageItemsNum); }; this .checkDatas.init=function(){ //点击“刷新”、“过滤”、“清除过滤”时执行 this .idKey = idKey ? idKey : 'id' ; this .allIncludedIds = []; this .allExcludedIds = []; this .textAllPages = '全选未启用,没有选择任何项!' ; this .stateAllPages = false ; this .stateThisPage = false ; }; this .checkDatas.clickAllPages = function (itemArray) { //所有页所有条目全选复选框被点击时执行的函数 if ( this .stateAllPages){ if ( this .allExcludedIds.length>0){ this .stateAllPages = true ; this .stateThisPage = true ; this .textAllPages= '全选已启用,没有排除任何项!' ; itemArray.forEach(function (item) { item.state = true ; }); } else if ( this .allExcludedIds.length==0){ this .stateAllPages = false ; this .stateThisPage = false ; this .textAllPages= '全选未启用,没有选择任何项!' ; itemArray.forEach(function (item) { item.state = false ; }); } } else { this .stateAllPages = true ; this .stateThisPage = true ; this .textAllPages= '全选已启用,没有排除任何项!' ; itemArray.forEach(function (item) { item.state = true ; }); } this .allExcludedIds = []; this .allIncludedIds = []; }; this .checkDatas.clickThisPage = function (itemsArray,allItemsNum) { //当前页所有条目全选复选框被点击时执行的函数 var that = this ; this .stateThisPage = ! this .stateThisPage itemsArray.forEach(function (item) { item.state = that.stateThisPage; if (item.state) { that.delID(item[that.idKey], that.allExcludedIds); that.addID(item[that.idKey], that.allIncludedIds); } else { that.delID(item[that.idKey], that.allIncludedIds); that.addID(item[that.idKey], that.allExcludedIds); } }); if ( this .stateAllPages){ if ( this .stateThisPage && this .allExcludedIds.length === 0){ this .textAllPages = '全选已启用,没有排除任何项!' ; } else { this .textAllPages = '全选已启用,已排除' + this .allExcludedIds.length + '项!排除项的ID为:' + this .allExcludedIds; } } else { if (! this .stateThisPage && this .allIncludedIds.length === 0){ this .textAllPages= '全选未启用,没有选择任何项!' ; } else { this .textAllPages = '全选未启用,已选择' + this .allIncludedIds.length + '项!选择项的ID为:' + this .allIncludedIds; } } }; this .checkDatas.clickSingleItem = function (item, itemsArray, allItemsNum) { //当前页单个条目复选框被点击时执行的函数 var that = this ; item.state = !item.state; if (item.state) { this .stateThisPage = true ; this .addID(item[ this .idKey], this .allIncludedIds); this .delID(item[ this .idKey], this .allExcludedIds); itemsArray.forEach( function (item) { if (!item.state) { that.stateThisPage = false ; } }); } else { this .stateThisPage = false ; this .addID(item[ this .idKey], this .allExcludedIds); this .delID(item[ this .idKey], this .allIncludedIds); } if ( this .stateAllPages){ if ( this .stateThisPage && this .allExcludedIds.length === 0){ this .textAllPages = '全选已启用,没有排除任何项!' ; } else { this .textAllPages = '全选已启用,已排除' + this .allExcludedIds.length + '项!排除项的ID为:' + this .allExcludedIds; } } else { if (! this .stateThisPage && this .allIncludedIds.length === 0){ this .textAllPages= '全选未启用,没有选择任何项!' ; } else { this .textAllPages = '全选未启用,已选择' + this .allIncludedIds.length + '项!选择项的ID为:' + this .allIncludedIds; } } }; this .checkDatas.signCheckbox = function (itemsArray) { //标注当前页被选中的条目,在翻页成功后执行。 var that = this ; if ( this .stateAllPages){ this .stateThisPage = true ; itemsArray.forEach(function (item) { var thisID = item[that.idKey]; var index = that.allExcludedIds.indexOf(thisID); if (index > -1) { item.state = false ; that.stateThisPage = false ; } else { item.state = true ; } }); } else { this .stateThisPage = true ; itemsArray.forEach( function (item) { var thisID = item[that.idKey]; var index = that.allIncludedIds.indexOf(thisID); if (index === -1) { item.state = false ; that.stateThisPage = false ; } }); } }; this .checkDatas.addID = function (id, idArray) { var index = idArray.indexOf(id); if (index === -1) { idArray.push(id); //如果当前页的单项既有勾选又有非勾选,这时勾选当前页全选,需要这个判断,以免重复添加 } }; this .checkDatas.delID = function (id, idArray) { var index = idArray.indexOf(id); if (index > -1) { idArray.splice(index, 1) } }; this .checkDatas.getResultOfCheckAndFilter = function (isShowFilter,filterOptions) { //获取发送给后台的所有参数。 var toServerDatas; var allIncludedIds = that.deepClone( this .allIncludedIds); var allExcludedIds = that.deepClone( this .allExcludedIds); if (! this .stateAllPages) { if (allIncludedIds.length === 0) { //return 弹窗告知:没有勾选项 } toServerDatas = { isSelectAll: false , allIncludedIds: allIncludedIds, } } else { toServerDatas = { //exclude isSelectAll: true , allExcludedIds: allExcludedIds, }; } if (isShowFilter) { for ( var key in filterOptions){ toServerDatas[key]=filterOptions[key] } } this .toServerDatas=toServerDatas; //这行代码在实际项目中不需要 return toServerDatas; } }, methods: { deepClone : function (arrayOrObject) { function isArray(value) { return {}.toString.call(value) === "[object Array]" ; } function isObject(value) { return {}.toString.call(value) === "[object Object]" ; } var target = null ; if (isArray(arrayOrObject)) target = []; if (isObject(arrayOrObject)) target = {}; for ( var key in arrayOrObject) { var value = arrayOrObject[key]; if (isArray(value) || isObject(value)) { target[key] = deepClone(value); } else { target[key] = value; } } return target; }, selectChange:function(eachPageItemsNum){ this .divideDatas.eachPageItemsNum = eachPageItemsNum; this .request(1,eachPageItemsNum); }, createDividePage : function () { var divideArray = []; var allPagesNum = this .divideDatas.allPagesNum; var nowPageNum = this .divideDatas.nowPageNum; if (allPagesNum >= 1 && allPagesNum <= 10) { for ( var i = 1; i <= allPagesNum; i++) { divideArray.push(i); } } else if (allPagesNum >= 11) { if (nowPageNum > 6) { divideArray.push(1); divideArray.push(2); divideArray.push(3); divideArray.push( '...' ); divideArray.push(nowPageNum - 1); divideArray.push(nowPageNum); } else { for (i = 1; i <= nowPageNum; i++) { divideArray.push(i); } } // 以上当前页的左边,以下当前页的右边 if (allPagesNum - nowPageNum >= 6) { divideArray.push(nowPageNum + 1); divideArray.push(nowPageNum + 2); divideArray.push( '...' ); divideArray.push(allPagesNum - 2); divideArray.push(allPagesNum - 1); divideArray.push(allPagesNum); } else { for ( var i = nowPageNum + 1; i <= allPagesNum; i++) { divideArray.push(i); } } } this .divideArray = divideArray; }, clickDividePage : function (stringOfNum, event ) { var allPagesNum = this .divideDatas.allPagesNum; var nowPageNum = this .divideDatas.nowPageNum; if (stringOfNum === 'front' && nowPageNum != 1) { nowPageNum--; } else if (stringOfNum === 'back' && nowPageNum != allPagesNum) { nowPageNum++; } else if (stringOfNum === 'leap' ) { if ( event .which != 13) return ; //不拦截情形:(1)聚焦输入框、按“Enter”键时;(2)点击“GO”时 var customNum = Math.ceil(parseFloat( this .customString)); if (customNum < 1 || customNum == 'NaN' ) { nowPageNum = 1; //不给提示 } else if (customNum > allPagesNum) { nowPageNum = allPagesNum; //不给提示 } else { nowPageNum = customNum; } } else { nowPageNum = Math.ceil(parseFloat(stringOfNum)); } this .request(nowPageNum, this .divideDatas.eachPageItemsNum); }, } } }, }) </script> </html> 二、Vue之五级联动--省、市、县、乡、村(含3个版本) <!DOCTYPE html> <html> <head> <meta charset= "UTF-8" > <title>Vue之五级联动--省、市、县、乡、村(含3个版本)</title> </head> <style type= "text/css" > .edit{ height:40px; line-height: 40px; } .paddingBottom{ padding-bottom: 40px; } .question- select { height: 60px; } .question- select select { border-radius: 5px; box-shadow: 0 0 5px #666; appearance: none; -webkit-appearance: none; -moz-appearance: none; border: none; outline: none; height: 40px; padding: 0 20px; color: #333; font-size: 22px; } .question- select select . short { width: 120px; } .question- select select . long { width: 240px; } .birth-year{ width:90px; margin-right: 20px; height: 100px; overflow-y: scroll; } .birth-month{ width:70px; margin-right: 20px; } .birth-date{ width:70px; } </style> <body> <!-- 以下是新版本(组件)HTML --> <div class = "edit" >以下是新版本(组件),符合实际应用场景</div> <div id= "newVersionComponent" > <five-grade :all-datas= "allDatas" ></five-grade> </div> <!-- 以下是新版本(普通)HTML --> <div class = "edit" >以下是新版本(普通),符合实际应用场景</div> <div id= "newVersionCommon" > <div class = "question-select" > < select v-model= "singleProvince" class = "short" @change= "selectName(singleProvince)" > <option v- for = "key in allProvinces" :value= "key" v-text= "key" ></option> </ select > < select v-model= "singleCity" v-show= "singleProvince" class = "short" @change= "selectName(singleProvince,singleCity)" > <option v- for = "key in allCitys" :value= "key" v-text= "key" ></option> </ select > < select v-model= "singleCounty" v-show= "singleCity" class = "short" @change= "selectName(singleProvince,singleCity,singleCounty)" > <option v- for = "key in allCountys" :value= "key" v-text= "key" ></option> </ select > < select v-model= "singleTown" v-show= "singleCounty" class = "long" @change= "selectName(singleProvince,singleCity,singleCounty,singleTown)" > <option v- for = "key in allTowns" :value= "key" v-text= "key" ></option> </ select > < select v-model= "singleVillage" v-show= "singleTown" class = "long" @change= "selectName(singleProvince,singleCity,singleCounty,singleTown,singleVillage)" > <option v- for = "key in allVillages" :value= "key" v-text= "key" ></option> </ select > </div> <div class = "paddingBottom" >{{address}}</div> </div> <!-- 以下是旧版本(普通)HTML --> <div class = "edit" >以下是旧版本(普通),不符合实际应用场景</div> <div id= "oldVersion" > <div class = "question-select" > < select v-model= "singleProvince" v- if = "singleProvince" class = "short" > <option v- for = "(value,key) in allProvinces" :value= "key" v-text= "key" ></option> </ select > < select v-model= "singleCity" v- if = "singleCity" class = "short" > <option v- for = "(value,key) in allCitys" :value= "key" v-text= "key" ></option> </ select > < select v-model= "singleCounty" v- if = "singleCounty" class = "short" > <option v- for = "(value,key) in allCountys" :value= "key" v-text= "key" ></option> </ select > < select v-model= "singleTown" v- if = "singleTown" class = "long" > <option v- for = "(value,key) in allTowns" :value= "key" v-text= "key" ></option> </ select > < select v-model= "singleVillage" v- if = "singleVillage" class = "long" > <option v- for = "(value,key) in allVillages" :value= "key" v-text= "key" ></option> </ select > </div> <div class = "paddingBottom" >{{address}}</div> </div> <div class = "edit" >以下是年月日分别选择</div> <div id= "yearMonthDate" > <div class = "question-select" > < select v-model= "yearMonthDate.year" @click= "clickYear" @change= "changeYear" class = "birth-year" > <option v- for = "item in years" :key= "item.key" :label= "item.key" :value= "item.value" > </option> </ select > < select v-model= "yearMonthDate.month" @click= "clickMonth" @change= "changeMonth" class = "birth-month" > <option v- for = "item in months" :key= "item.key" :label= "item.key" :value= "item.value" > </option> </ select > < select v-model= "yearMonthDate.day" @click= "clickDay" class = "birth-date" > <option v- for = "item in days" :key= "item.key" :label= "item.key" :value= "item.value" > </option> </ select > </div> <div class = "paddingBottom" >您选择的年月日是:{{yearMonthDate.year}}年{{yearMonthDate.month}}月{{yearMonthDate.day}}日</div> </div> </body> <script src= "https://cdn.jsdelivr.net/npm/vue/dist/vue.js" ></script> <!-- Vue.js v2.6.10 --> <script type= "text/javascript" > //以下是新版本(组件)JS Vue.component( 'five-grade' , { template: ` <div> <div class = "question-select" > < select v-model= "singleProvince" class = "short" @change= "selectName(singleProvince)" > <option v- for = "key in allProvinces" :value= "key" v-text= "key" ></option> </ select > < select v-model= "singleCity" v-show= "singleProvince" class = "short" @change= "selectName(singleProvince,singleCity)" > <option v- for = "key in allCitys" :value= "key" v-text= "key" ></option> </ select > < select v-model= "singleCounty" v-show= "singleCity" class = "short" @change= "selectName(singleProvince,singleCity,singleCounty)" > <option v- for = "key in allCountys" :value= "key" v-text= "key" ></option> </ select > < select v-model= "singleTown" v-show= "singleCounty" class = "long" @change= "selectName(singleProvince,singleCity,singleCounty,singleTown)" > <option v- for = "key in allTowns" :value= "key" v-text= "key" ></option> </ select > < select v-model= "singleVillage" v-show= "singleTown" class = "long" @change= "selectName(singleProvince,singleCity,singleCounty,singleTown,singleVillage)" > <option v- for = "key in allVillages" :value= "key" v-text= "key" ></option> </ select > </div> <div class = "paddingBottom" >{{address}}</div> </div> `, props: { allDatas: { type: Object } }, data: function(){ return { allProvinces: [], singleProvince: '' , allCitys: [], singleCity: '' , allCountys: [], singleCounty: '' , allTowns: [], singleTown: '' , allVillages: [], singleVillage: '' , address: '' , } }, beforeMount: function () { this .selectName(); }, methods: { selectName: function(singleProvince,singleCity,singleCounty,singleTown,singleVillage){ var siteArray = [singleProvince,singleCity,singleCounty,singleTown,singleVillage]; var modelArray = [ 'singleProvince' , 'singleCity' , 'singleCounty' , 'singleTown' , 'singleVillage' ]; var optionsArray = [ 'allProvinces' , 'allCitys' , 'allCountys' , 'allTowns' , 'allVillages' ]; var allDatasNext; var address = "你选择的地址是:" ; for ( var i=0;i<siteArray.length;i++){ //遍历数组所有项 if (!siteArray[i]) this [modelArray[i]] = '' ; } for ( var i=0;i<siteArray.length;i++){ //遍历数组至undefined第1次出现时停止 allDatasNext = i == 0 ? this .allDatas : allDatasNext[siteArray[i-1]]; if (!siteArray[i]) { var array = []; for ( var key in allDatasNext) { array.push(key) } this [optionsArray[i]] = array; break ; } } if ( this .singleProvince) address += this .singleProvince; if ( this .singleCity) address += '-' + this .singleCity; if ( this .singleCounty) address += '-' + this .singleCounty; if ( this .singleTown) address += '-' + this .singleTown; if ( this .singleVillage) address += '-' + this .singleVillage; this .address = address; } }, }); new Vue({ el: '#newVersionComponent' , data(){ return { allDatas : makeallDatas() } }, methods:{ } }) //以下是新版本(普通)JS var allDatas = makeallDatas(); var vm = new Vue({ el: '#newVersionCommon' , data: { allDatas: allDatas, allProvinces: [], singleProvince: '' , allCitys: [], singleCity: '' , allCountys: [], singleCounty: '' , allTowns: [], singleTown: '' , allVillages: [], singleVillage: '' , address: '' , }, beforeMount: function () { this .selectName() }, methods: { selectName: function(singleProvince,singleCity,singleCounty,singleTown,singleVillage){ var siteArray = [singleProvince,singleCity,singleCounty,singleTown,singleVillage]; var modelArray = [ 'singleProvince' , 'singleCity' , 'singleCounty' , 'singleTown' , 'singleVillage' ]; var optionsArray = [ 'allProvinces' , 'allCitys' , 'allCountys' , 'allTowns' , 'allVillages' ]; var allDatasNext; var address = "你选择的地址是:" ; for ( var i=0;i<siteArray.length;i++){ //遍历数组所有项 if (!siteArray[i]) this [modelArray[i]] = '' ; } for ( var i=0;i<siteArray.length;i++){ //遍历数组至undefined第1次出现时停止 allDatasNext = i == 0 ? this .allDatas : allDatasNext[siteArray[i-1]]; if (!siteArray[i]) { var array = []; for ( var key in allDatasNext) { array.push(key) } this [optionsArray[i]] = array; break ; } } if ( this .singleProvince) address += this .singleProvince; if ( this .singleCity) address += '-' + this .singleCity; if ( this .singleCounty) address += '-' + this .singleCounty; if ( this .singleTown) address += '-' + this .singleTown; if ( this .singleVillage) address += '-' + this .singleVillage; this .address = address; } } }); //以下是旧版本(普通)JS var allProvinces = makeallDatas(); var vm = new Vue({ el: '#oldVersion' , data: { allProvinces: allProvinces, singleProvince: '北京市' , allCitys: {}, singleCity: '' , allCountys: {}, singleCounty: '' , allTowns: {}, singleTown: '' , allVillages: {}, singleVillage: '' , address: '' , }, beforeMount: function () { this .update( "allProvinces" , "singleProvince" , "allCitys" , "singleCity" ) }, methods: { update: function (thisall,thisName,nextall,nextName) { //1个上级更新,会导致1个下级更新,进而导致1个下下级的更新... for ( var key in this [thisall]) { if (key === this [thisName]) { this [nextall] = this [thisall][key]; for ( var key in this [nextall]) { this [nextName] = key; break ; } } } var address = "你选择的地址是:" ; if ( this .singleProvince) address += this .singleProvince; if ( this .singleCity) address += '-' + this .singleCity; if ( this .singleCounty) address += '-' + this .singleCounty; if ( this .singleTown) address += '-' + this .singleTown; if ( this .singleVillage) address += '-' + this .singleVillage; this .address = address; } }, watch: { singleProvince: function () { this .update( "allProvinces" , "singleProvince" , "allCitys" , "singleCity" ) }, singleCity: function () { this .update( "allCitys" , "singleCity" , "allCountys" , "singleCounty" ) }, singleCounty: function () { this .update( "allCountys" , "singleCounty" , "allTowns" , "singleTown" ) }, singleTown: function () { this .update( "allTowns" , "singleTown" , "allVillages" , "singleVillage" ) } } }) //以下是年月日分别选择(普通)JS var vm = new Vue({ el: '#yearMonthDate' , data: function(){ return { yearMonthDate: { year:1900, month:1, day:1, }, years: [{ key: 1900, value: 1900, }], months: [{ key: 1, value: 1, }], days: [{ key: 1, value: 1, }], address: '' , } }, beforeMount: function () { //this.selectName() }, methods: { clickYear: function(){ this .years.length = 0; var thisYear = new Date().getFullYear(); for ( var i = 1900; i <= thisYear; i++){ this .years.push({ key: i, value: i, }) } }, changeYear: function(){ this .yearMonthDate.month = 1 this .yearMonthDate.day = 1 }, clickMonth: function(){ this .months.length = 0; for ( var i = 1; i <= 12; i++){ this .months.push({ key: i, value: i, }) } this .yearMonthDate.day = 1 }, changeMonth: function(){ this .yearMonthDate.day = 1 }, clickDay: function(){ this .days.length = 0; var dayNum = 0; var longMonth = [1,3,5,7,8,10,12]; var shortMonth = [4,6,9,11]; if (longMonth.indexOf( this .yearMonthDate.month) > -1){ dayNum = 31; } else if (shortMonth.indexOf(yearMonthDate.month) > -1){ dayNum = 30; } else if ( this .yearMonthDate.month === 2){ //1900年及以后的闰年 if ( this .yearMonthDate.year != 1900 && this .yearMonthDate.year % 4 === 0){ dayNum = 29; } else { dayNum = 28; } } for ( var i = 1; i <= dayNum; i++){ this .days.push({ key: i, value: i, }) } } } }); //以下是所有版本JS function makeallDatas() { var allDatas = { "北京市" : { "区" : { "通州区" : { "中仓街道办事处" : { "滨河社区居委会" : "110112001029" , "运河湾社区居委会" : "110112001030" }, "漷县镇" : { "后元化村委会" : "110112106260" , "前元化村委会" : "110112106261" } }, "昌平区" : { "天通苑南街道办事处" :{ "东辰社区居委会" : "110114009001" , "佳运园社区居委会" : "110114009002" , "天通苑第二社区居委会" : "110114009003" , "天通西苑第一社区居委会" : "110114009004" , "天通东苑第一社区居委会" : "110114009005" , "天通东苑第二社区居委会" : "110114009006" , "天通苑第一社区居委会" : "110114009007" , "嘉诚花园社区居委会" : "110114009008" , "清水园社区居委会" : "110114009009" , "北方明珠社区居委会" : "110114009010" , "天通东苑第四社区居委会" : "110114009011" , "顶秀清溪社区居委会" : "110114009012" , "奥北中心社区居委会" : "110114009013" , "陈营村委会" : "110114009201" }, "霍营街道办事处" : { "华龙苑南里社区居委会" : "110114010001" , "华龙苑北里社区居委会" : "110114010002" , "蓝天园社区居委会" : "110114010003" , "天鑫家园社区居委会" : "110114010004" , "霍营小区社区居委会" : "110114010005" , "上坡佳园社区居委会" : "110114010006" , "华龙苑中里社区居委会" : "110114010007" , "流星花园社区居委会" : "110114010008" , "龙回苑社区居委会" : "110114010009" , "和谐家园社区居委会" : "110114010010" , "田园风光雅苑社区居委会" : "110114010011" , "龙锦苑一区社区居委会" : "110114010012" , "龙锦苑东一区社区居委会" : "110114010013" , "龙锦苑东二区社区居委会" : "110114010014" , "龙锦苑东五区社区居委会" : "110114010015" , "龙锦苑东三区社区居委会" : "110114010016" , "龙锦苑东四区社区居委会" : "110114010017" , "紫金新干线社区居委会" : "110114010018" , "霍家营村委会" : "110114010201" } } }, "县" : { "密云县" : { "密云镇" : { "小唐庄社区居委会" : "110228100001" , "李各庄社区居委会" : "110228100002" , "大唐庄社区居委会" : "110228100003" , "季庄村委会" : "110228100205" , }, "溪翁庄镇" : { "东智北村委会" : "110228101209" , "石墙沟村委会" : "110228101210" , "黑山寺村委会" : "110228101211" , "立新庄村委会" : "110228101212" , }, }, "延庆县" : { "旧县镇" : { "常里营村委会" : "110229104215" , "盆窑村委会" : "110229104216" , "团山村委会" : "110229104217" , "大柏老村委会" : "110229104218" , }, "珍珠泉乡" : { "双金草村委会" : "110229214209" , "小川村委会" : "110229214210" , "小铺村委会" : "110229214211" , "仓米道村委会" : "110229214212" , } } } }, "河南省" : { "郑州市" : { "金水区" : { "凤凰台街道办事处" : { "凤凰台社区居民委员会" : "410105013004" , "王庄社区居民委员会" : "410105013005" , "张庄社区居民委员会" : "410105013006" , "凤凰城社区居民委员会" : "410105013007" , }, "金光路街道办事处" : { "徐庄村委会" : "410105564201" , "贾陈村委会" : "410105564202" , "柳园口村委会" : "410105564203" , "马楼村委会" : "410105564204" , } }, "登封市" : { "嵩阳街道办事处" : { "玉溪路居委会" : "410185001014" , "苹果园居委会" : "410185001015" , "颖河路居委会" : "410185001016" , "守敬路居委会" : "410185001017" , }, "少林街道办事处" : { "塔沟居委会" : "410185002001" , "少林居委会" : "410185002002" , "耿庄村委会" : "410185002203" , "王庄村委会" : "410185002204" , }, "送表矿区" : { "东送表村委会" : "410185400201" , "梁庄村委会" : "410185400202" , "安庄村委会" : "410185400203" , "刘楼村委会" : "410185400204" , } } }, "信阳市" : { "浉河区" : { "老城街道办事处" : { "义阳居委会" : "411502001001" , "三里店居委会" : "411502001003" , "东方红居委会" : "411502001004" , "浉河居委会" : "411502001007" , }, "民权街道办事处" : { "民权居委会" : "411502002001" , "新生居委会" : "411502002002" , "成功居委会" : "411502002003" , "白果树居委会" : "411502002004" , }, "车站街道办事处" : { "工区东居委会" : "411502003001" , "工区路居委会" : "411502003002" , "六里棚居委会" : "411502003003" , "新公房居委会" : "411502003004" , } }, "固始县" : { "段集镇" : { "街道居委会" : "411525109001" , "段集村委会" : "411525109201" , "棠树岗村委会" : "411525109202" , "青峰村委会" : "411525109203" , "下楼村委会" : "411525109204" , "桂岭村委会" : "411525109205" , "窑沟村委会" : "411525109206" , "五尖山村委会" : "411525109207" , "柳林村委会" : "411525109208" , "齐山村委会" : "411525109209" , "钓鱼台村委会" : "411525109210" , "蒋营村委会" : "411525109211" , "庙山村委会" : "411525109212" , "汪旱庄村委会" : "411525109213" , "乐道村委会" : "411525109214" , "姚老家村委会" : "411525109215" , "赵营村委会" : "411525109216" , "童庙村委会" : "411525109217" , "高庙村委会" : "411525109218" }, "武庙集镇" : { "街道居委会" : "411525113001" , "汪小庄村委会" : "411525113201" , "黄土岭村委会" : "411525113202" , "平阳村委会" : "411525113203" , "长江河村委会" : "411525113204" , "锁口村委会" : "411525113205" , "皮冲村委会" : "411525113206" , "刘中楼村委会" : "411525113207" , "迎水寺村委会" : "411525113208" , "余楼村委会" : "411525113209" , "钱老楼村委会" : "411525113210" , "新店村委会" : "411525113211" , "徐小店村委会" : "411525113212" , "邓岭村委会" : "411525113213" , "太平村委会" : "411525113214" , "汪楼村委会" : "411525113215" , "李瓦房村委会" : "411525113216" }, "祖师庙镇" : { "祖师庙居委会" : "411525117001" , "仰天洼社区居委会" : "411525117002" , "小店村委会" : "411525117201" , "王行村委会" : "411525117202" , "大冲村委会" : "411525117203" , "松林村委会" : "411525117204" , "刘楼村委会" : "411525117205" , "羁马村委会" : "411525117206" , "黄楼村委会" : "411525117207" , "彭畈村委会" : "411525117208" , "童圩村委会" : "411525117209" , "仓房村委会" : "411525117210" , "毛店村委会" : "411525117211" , "万岗村委会" : "411525117212" , "七冲村委会" : "411525117213" , "三区村委会" : "411525117214" , "杨楼村委会" : "411525117215" } }, "息县" : { "杨店乡" : { "杨店村委会" : "411528204200" , "安寨村委会" : "411528204201" , "何庄村委会" : "411528204202" , "李大庄村委会" : "411528204203" , }, "张陶乡" : { "张陶村委会" : "411528205200" , "曹林村委会" : "411528205201" , "陈圈行村委会" : "411528205202" , "大陈庄村委会" : "411528205203" , }, "白土店乡" : { "白土店村委会" : "411528206200" , "白衣阁村委会" : "411528206201" , "大江庄村委会" : "411528206202" , "桂庄村委会" : "411528206203" , }, "岗李店乡" : { "岗李店村委会" : "411528207200" , "大彭庄村委会" : "411528207201" , "方老庄村委会" : "411528207202" , "贾后寨村委会" : "411528207203" , } } }, }, }; return allDatas; } </script> </html> 三、2种三层弹窗组件之simple-dialog 1、不可拖拽 <!DOCTYPE html> <html> <head> <meta charset= "utf-8" > <title>Vue多层弹窗</title> <script src= "https://cdn.staticfile.org/vue/2.2.2/vue.min.js" ></script> <style> .simpleDialog { position: fixed ; width: 100%; height: 100%; top: 0; left: 0; display: flex; justify-content: center; align-items: center; } .simpleDialog .mask { position: fixed ; width: 100%; height: 100%; top: 0; left: 0; background: black; opacity: 0.5; } .simpleDialog .content { position: fixed ; background: white; opacity: 1; display: flex; flex-direction: column; } .simpleDialog .content .title { display: flex; background: blue; color: white; padding: 10px; cursor: pointer; } .simpleDialog .content .conform { display: flex; justify-content: center; padding: 10px; background: blue; } </style> </head> <body> <div id= "el" > <button @click= "clickButton()" style= "margin-top: 30px;" > 点击-出现-弹窗 </button> <simple-dialog :required-data= "requiredDataOut" > 插槽一 <simple-dialog :required-data= "requiredDataMid" > 插槽二 <simple-dialog :required-data= "requiredDataIn" > 插槽三 </simple-dialog> </simple-dialog> </simple-dialog> </div> <script> Vue.component( 'simple-dialog' , { template: ` <div> <div class = "simpleDialog" v-show= "requiredData.isShow" > <div class = "mask" v-show= "requiredData.isShow" ></div> <div class = "content" v-show= "requiredData.isShow" > <div class = "title" > <span>系统消息</span> </div> <div :style= "{width:requiredData.width||'800px',height:requiredData.height||'400px'}" > <slot></slot> </div> <div class = "conform" > <button v- on :click= "close()" >关闭</button> <button v- on :click= "open()" >打开</button> </div> <div> </div> </div> `, props: { requiredData: { type: Object } }, data: function() { return {} }, methods: { close: function () { this .requiredData.isShow = false ; if ( this .requiredData.closeFn) this .requiredData.closeFn(); }, open: function () { if ( this .requiredData.openFn) this .requiredData.openFn(); } } }); new Vue({ el: '#el' , data(){ var that = this ; return { requiredDataOut : { isShow : false , width : '900px' , height : '600px' , openFn : function () { that.requiredDataMid.isShow = true ; } }, requiredDataMid : { isShow : false , width : '600px' , height : '400px' , openFn : function () { that.requiredDataIn.isShow = true ; }, }, requiredDataIn : { isShow : false , width : '300px' , height : '200px' , }, // 一层弹窗可以如下使用 // requiredDataOut = { // isShow : false, // }; // clickButton() { // requiredDataOut.isShow = true; // }; } }, methods:{ clickButton() { this .requiredDataOut.isShow = true ; } } }) </script> </body> </html> 2、可拖拽(含插槽) <!DOCTYPE html> <html> <head> <meta charset= "utf-8" > <title>Vue多层弹窗</title> <script src= "https://cdn.staticfile.org/vue/2.2.2/vue.min.js" ></script> <script> function drag(wholeTitleId, wholeContentId) { var wholeTitleId = wholeTitleId|| 'titleId' ; var wholeContentId = wholeContentId|| 'contentId' ; var oDiv = document.getElementById(wholeContentId); if (!oDiv) return ; oDiv.onmousedown = down; function processThis(fn, nowThis) { return function ( event ) { fn.call(nowThis, event ); }; } function down( event ) { event = event || window. event ; if ( event .target.id != wholeTitleId) return ; this .initOffsetLeft = this .offsetLeft; this .initOffsetTop = this .offsetTop; this .initClientX = event .clientX; this .initClientY = event .clientY; this .maxOffsetWidth = (document.documentElement.clientWidth || document.body.clientWidth) - this .offsetWidth; this .maxOffsetHeight = (document.documentElement.clientHeight || document.body.clientHeight) - this .offsetHeight; if ( this .setCapture) { this .setCapture(); this .onmousemove = processThis(move, this ); this .onmouseup = processThis(up, this ); } else { document.onmousemove = processThis(move, this ); document.onmouseup = processThis(up, this ); } } function move( event ) { var nowLeft = this .initOffsetLeft + ( event .clientX - this .initClientX); var nowTop = this .initOffsetTop + ( event .clientY - this .initClientY); this .style.left = nowLeft + 'px' ; this .style.top = nowTop + 'px' ; } function up() { if ( this .releaseCapture) { this .releaseCapture(); this .onmousemove = null ; this .onmouseup = null ; } else { document.onmousemove = null ; document.onmouseup = null ; } } }; </script> <style> .simpleDialog { position: fixed ; width: 100%; height: 100%; top: 0; left: 0; display: flex; justify-content: center; align-items: center; } .simpleDialog .mask { position: fixed ; width: 100%; height: 100%; top: 0; left: 0; background: black; opacity: 0.5; } .simpleDialog .content { position: fixed ; background: white; opacity: 1; display: flex; flex-direction: column; } .simpleDialog .content .title { display: flex; background: blue; color: white; padding: 10px; cursor: pointer; } .simpleDialog .content .conform { display: flex; justify-content: center; padding: 10px; background: blue; } </style> </head> <body> <div id= "el" > <button @click= "clickButton()" style= "margin-top: 30px;" > 点击-出现-弹窗 </button> <simple-dialog :required-data= "requiredDataOut" > 插槽一 <simple-dialog :required-data= "requiredDataMid" > 插槽二 <simple-dialog :required-data= "requiredDataIn" > 插槽三 </simple-dialog> </simple-dialog> </simple-dialog> </div> <script> Vue.component( 'simple-dialog' , { template: ` <div> <div class = "simpleDialog" v-show= "requiredData.isShow" > <div class = "mask" v-show= "requiredData.isShow" ></div> <div class = "content" v-show= "requiredData.isShow" :id= "requiredData.contentId||'contentId'" > <div class = "title" :id= "requiredData.titleId||'titleId'" > <span>系统消息</span> </div> <div :style= "{width:requiredData.width||'800px',height:requiredData.height||'400px'}" > <slot></slot> </div> <div class = "conform" > <button v- on :click= "close()" >关闭</button> <button v- on :click= "open()" >打开</button> </div> <div> </div> </div> `, props: { requiredData: { type: Object } }, data: function() { return {} }, methods: { close: function () { this .requiredData.isShow = false ; if ( this .requiredData.closeFn) this .requiredData.closeFn(); var content = this .requiredData.contentId; document.getElementById(content).style.cssText = "position:fixed;display:flex;" ; }, open: function () { if ( this .requiredData.openFn) this .requiredData.openFn(); } }, }); new Vue({ el: '#el' , data(){ var that = this ; return { requiredDataOut : { isShow : false , width : '900px' , height : '600px' , titleId : "titleId1" , contentId : "contentId1" , openFn : function () { that.requiredDataMid.isShow = true ; drag(that.requiredDataMid.titleId,that.requiredDataMid.contentId); } }, requiredDataMid : { isShow : false , width : '600px' , height : '400px' , titleId : "titleId2" , contentId : "contentId2" , openFn : function () { that.requiredDataIn.isShow = true ; drag(that.requiredDataIn.titleId,that.requiredDataIn.contentId); }, }, requiredDataIn : { isShow : false , width : '300px' , height : '200px' , titleId : "titleId3" , contentId : "contentId3" , }, // 一层弹窗可以如下使用 // requiredDataOut = { // isShow : false, // }; // clickButton() { // requiredDataOut.isShow = true; // }; } }, methods:{ clickButton() { this .requiredDataOut.isShow = true ; drag( this .requiredDataOut.titleId, this .requiredDataOut.contentId); } } }) </script> </body> </html> 四、2种三层弹窗组件之el-dialog <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <meta name= "viewport" content= "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" > <title>vue2.6.10组件之el-dialog多层弹窗</title> <script src= "https://cdn.bootcss.com/vue/2.6.10/vue.min.js" ></script> <script src= "https://cdn.bootcss.com/element-ui/2.10.1/index.js" ></script> <link href= "https://cdn.bootcss.com/element-ui/2.10.1/theme-chalk/index.css" rel= "stylesheet" > <style> #app{ display: flex; justify-content: space-between; } </style> </head> <body> <div id= "app" > <el-button type= "text" @click= "outerVisible = true" >点击打开外层弹窗</el-button> <el-dialog width= "70%" title= "外层" :visible.sync= "outerVisible" > 以下是外层弹窗的插槽<br/> <div style= "height:200px;border:1px solid #ccc;padding:20px;" > width= "70%" ,决定弹-窗的宽<br/> style= "height:200px" ,通过给弹-窗插槽的部分标签设置高,决定弹-窗的高,如此框<br/> :visible.sync= "middleVisible" ,传递引用,此处改变,别处也改变<br/> :visible= "middleVisible" ,传递普通值,此处改变,别处不改变<br/> <el-dialog width= "50%" title= "中层" :visible.sync= "middleVisible" append-to-body > 以下是中层弹-窗的插槽<br/> <el-dialog width= "30%" title= "内层" :visible.sync= "innerVisible" append-to-body > 以下是内层弹-窗的插槽<br/> <div slot= "footer" class = "dialog-footer" > <el-button @click= "innerVisible = false" >关闭内层</el-button> <el-button type= "primary" @click= "innerVisible = false" >关闭内层</el-button> </div> 以上是内层弹-窗的插槽<br/> </el-dialog> <div slot= "footer" class = "dialog-footer" > <el-button @click= "middleVisible = false" >关闭中层</el-button> <el-button type= "primary" @click= "innerVisible = true" >打开内层</el-button> </div> 以上是中层弹-窗的插槽<br/> </el-dialog> </div> <div slot= "footer" class = "dialog-footer" > <el-button @click= "outerVisible = false" >关闭外层</el-button> <el-button type= "primary" @click= "middleVisible = true" >打开中层</el-button> </div> 以上是外层弹-窗的插槽(代码中,此句位于按钮下面)<br/> </el-dialog> </div> </body> <script> new Vue({ el: '#app' , data() { return { outerVisible: false , middleVisible: false , innerVisible: false }; }, methods: { }, components: { }, }) </script> </html> 五、vue报错与解决 1、问题1 (1)现象,把主分支拉到本地,直接运行npm run dev,出错 (2)解决,把mock文件夹里,新生成的压缩文件如fkdsfsdlsdf.js删除;或者运行node -v,看node版本是不是在16以上 2、问题2 (1)现象,[2024-06-27 14:01:41] waiting for changes... (2)说明, A、编译成功了,正在监听文件改动 B、这不是一个完整的项目 C、编译成功的文件没有index.html文件可供插入 3、问题3 (1)现象,[Vue warn]: Invalid prop: custom validator check failed for prop "type" . vue.runtime.esm.js? (2)解决, A、这个问题不影响项目的正常运行 B、出现这个报错的原因是,iview支持数字类型的输入,vue自带的-vue错误检查工具-vue.runtime.esm.js-不支持数字类型的输入,因而报错 C、解决方案,开发者应当在浏览器安装-vue错误检查插件-https: //github.com/vuejs/vue-devtools,取代vue.runtime.esm.js,给vue检查错误 4、问题4,用插件vod-js-sdk-v6上传视频时 来源,https: //cloud.tencent.com/developer/ask/260695 (1)现象,报错“Error: ugc upload | signature verify forbidden” (2)原因, A、前端向后台索要签名,后台用小权限“腾讯账户”向腾讯索要签名, B、腾讯给后台小权限签名,后台给前端小权限签名,前端将小权限签名发给腾讯,腾讯给前端报错 (3)解决,让后台换用大权限“腾讯账户” 5、问题5 (1)现象,不是第一页的最后一页为空白 (2)原因,最后一页不是第一页,删除最后一页的唯一项,然后请求当前页数据 (3)解决, delModelTrainings({trainingId: row.trainingId}).then(() => { ElMessage.success( '删除成功' ); var total = (page.value.pageNum - 1)*page.value.pageSize + 1; //当前页情况 //当前页第1项的序号=数据的总数(当前页是最后1页且只有1项) //当前页第1项的序号>每页条数(当前页不是第1页) if (total === page.value.count && total > page.value.pageSize){ page.value.pageNum--; } listData(); }) 6、问题6 (1)现象,:src 文件路径错误问题的解决方法 (2)解决, <template> <img :src= "item.url" alt= "logo" /> </template> import background from '@/assets/image/background.png' var collect = reactive([ { url: background, // url: '/src/assets/images/logo.png' 注释这样的写法会出错 teacher: "讲师:李老师" , } ]); 7、问题7 (1)现象,el- select 的blur事件不能通过{trigger: 'blur' }触发,只能通过{@blur= "selectBlur" }触发 (2)解决, <el-form-item label= "所属页卡" prop= "card_id" > <el- select v-model= "form.card_id" placeholder= "请选择所属页卡" @blur= "selectBlur" > <el-option v- for = "item in configType" :key= "item.value" :label= "item.label" :value= "item.value" > </el-option> </el- select > </el-form-item> rules: { //trigger: 'blur'无效,trigger: 'change'有效, card_id:[{ required: true , message: '请选择所属页卡' , trigger: 'change' , validator: function(rule, value, callback){ if (!value) { callback( new Error()); } else { callback() } } }], }, selectBlur(){ this .$refs[ "form" ].validateField( "card_id" ); }, 8、问题8,出现在vue2.6.0以后的版本中 报错信息:[VUE ERROR] Invalid default value for prop "slides" : Props with type Object/Array must use a factory function to return the default value 错误原因:当给子组件设置 props 属性时,如果参数类型是 Array 或 Object 它的默认值必须是由工场函数返回,不能直接赋值 (1)现象,黄字错误 props: { sizeRadio: { type: Array, default : [] } sizeRadio: { type: Object, default : {} } }, (2)解决, props: { sizeRadio: { type: Array, default : function() { return [] } } sizeRadio: { type: Object, default : function() { return {} } } }, 9、问题9 (1)现象,一级swiper与二级swiper所需swiper包的版本不一致,运行“npm install”出现下面问题, 问题来源,https: //blog.csdn.net/weixin_52509007/article/details/124165325 "dependencies" : { "swiper" : "^8.1.0" , //一级插件 "vue-awesome-swiper" : "^4.1.1" , //内部也有swiper二级插件,但版本与上面不一样 }, npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: vue2-standard-demo@0.1.0 npm ERR! Found: swiper@8.1.0 npm ERR! node_modules/swiper npm ERR! swiper @"^8.1.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer swiper @"^5.2.0" from vue-awesome-swiper@4.1.1 npm ERR! node_modules/vue-awesome-swiper npm ERR! vue-awesome-swiper @"4.1.1" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See D:\app\nodejs\node_cache\eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in : npm ERR! D:\app\nodejs\node_cache\_logs\2022-04-14T01_48_57_987Z-debug-0.log (2)解决, 初步解决:更改一级以适应二级,问题消失,但安装结束后,node_modules被自动删除; 最终解决:运行“yarn”,彻底解决这个问题 10、问题10,汉化 (1)方案一,在App.vue中 <script > import { defineComponent } from 'vue' import { ElConfigProvider } from 'element-plus' import zhCn from 'element-plus/dist/locale/zh-cn.mjs' export default defineComponent({ components: { ElConfigProvider, }, setup() { return { locale: zhCn, } }, }) </script> <template> <div style= "height:100%" > <el-config-provider :locale= "locale" > <router-view v-slot= "{ Component }" > <keep-alive> <component : is = "Component" /> </keep-alive> </router-view> </el-config-provider> </div> </template> (2)方案二,在main.js中 import ElementPlus from 'element-plus' import zhCn from 'element-plus/es/locale/lang/zh-cn' app.use(ElementPlus, { locale: zhCn }) app.mount( '#app' ) 六、vue效果与实现 1、表单 (1)表单项只显示标签 <el-form-item label= "内容配置" class = "blue-label" ></el-form-item> (2)表单项不显示标签 <el-form-item label-width= "80px" > <template #label> <span></span> </template> <el-button type= "primary" size= "mini" icon= "el-icon-search" @click= "handleQuery" >查询</el-button> </el-form-item> (3)一行显示多个表单项 <el-form :model= "nowCard" :label-position= "'right'" label-width= "130px" > <el-row> <el-col :span= "10" > <el-form-item label= "页卡名称" > <el-input v-model= "nowCard.card_name" type= "text" maxlength= "200" placeholder= "请输入页卡名称" style= "width:300px;" :disabled= "nowCard.create_user == 'system'" /> </el-form-item> </el-col> <el-col :span= "10" > <el-form-item label= "页卡序号" > <el-input v-model= "nowCard.order_index" type= "text" maxlength= "200" :placeholder= "'请输入页卡序号('+ addPagecardText +'时不输入)'" style= "width:300px;" :disabled= "nowCard.isAdd" /> </el-form-item> </el-col> </el-row> </el-form> 2、表格 (1)表体超高,出现滚动条,常用于弹窗中 <el-table :data= "otherContent" height= "400" overflow= "auto" > (2)节目单表格 A、需求 a、最上面一行是周,周一到周日 b、最左边一栏是时间,00:00--24:00 B、实现 a、遍历时间,遍历数据,用对象存储时间、周一到周日的数据,把对象存储到数组里 b、遍历数组,合并同行不同栏 c、遍历数组,合并同栏不同行 (3)el-popconfirm飞走和el-input显示不聚焦 <el-table-column prop= "title" label= "名称" > <template # default = "scope" > <div style= "display: flex;" v-show= "!scope.row.isShowEdit" > <div class = "document-title" @click= "cellClick(scope.row)" >{{ scope.row.title }}</div> <div :style= "{visibility:scope.row.isShowOperator}" > //1、用visibility代替v-show,以免el-popconfirm飞走 <el-tooltip content= "重命名" placement= "top" effect= "light" > <svg-icon icon- class = "rename" @click= "renameClick(scope.row)" class = "svg-icon" ></svg-icon> </el-tooltip> <span style= "padding: 0 4px" ></span> <el-popconfirm confirm-button-text= "确定" cancel-button-text= "取消" cancel-button-type= "default" width= "180px" :enterable= "true" placement= "top" title= "你确定要删除吗?" effect= "light" @confirm= "deleteItem(scope.row)" > <template #reference> <span> <el-tooltip content= "删除" placement= "top" effect= "light" > <svg-icon icon- class = "del" class = "svg-icon" ></svg-icon> </el-tooltip> </span> </template> </el-popconfirm> </div> </div> <div style= "display: flex;" v-show= "scope.row.isShowEdit" > <el-input : ref = "getRef" v-model= "scope.row.title" placeholder= "请输入" @blur= "renameBlur(scope.row)" /> </div> </template> </el-table-column> <textView :fileVisible= "fileVisible" :item= "modelFile" : readonly = "readonly" @submit= "update" @close= "hideFileVisible" ></textView> <pdfView :fileVisible= "showPDFView" :item= "modelPDFFile" @close= "hidePDFVisible" ></pdfView> <docView :fileVisible= "showDOCView" :item= "modelDOCFile" @close= "hideDOCVisible" ></docView> function getRef(InputRef) { //2、根据:ref="函数"的特性,实现el-input显示即聚焦 // 附、element-plus标签的ref属性 // (1)ref="变量",xxx.value,可用于访问DOM元素或子组件实例 // (2):ref="函数", // A、当元素或组件挂载到DOM上时,该函数会被调用,并且会将元素或组件的实例作为参数传递给这个函数 // B、当元素或组件从DOM中移除时,该函数会再次被调用,此时传递null作为参数 if (InputRef) InputRef.focus(); } // 附、页面联动闪烁,控制台报错 // 从modelFile中,modelPDFFile和modelDOCFile // 分开,一个维持旧值不显示,一个赋新值显示,页面不会联动闪烁,控制台不会报错 // 不分开,两个同时赋新值显示,一个显示,一个不显示,页面联动闪烁,控制台报错 // 正常的逻辑是,一开始就初始化所有值,再根据情况具体赋值 function viewItem(row) { if (row.docType == 'html' ){ window,open(row.externalUrl) } else if (row.docType == 'pdf' ){ showDOCView.value = false ; showPDFView.value = true ; modelPDFFile.value = row; modelPDFFile.value.url = row.publicUrl; //此处产生跨域 } else if (row.docType == 'word' ){ showDOCView.value = true ; showPDFView.value = false ; modelDOCFile.value = row; modelDOCFile.value.url = row.publicUrl; //此处产生跨域 } else { showDOCView.value = false ; showPDFView.value = false ; fileVisible.value = true ; readonly .value = true ; modelFile.value = row; } } 3、多行收缩为2行,点击则“用动画”展开 (1)隐藏Outer,不能触发点击事件 (2)获取初始数据;内层显示full区域,异步计算full区域的高度并存储、显示fold区域、隐藏full区域 (3)显示Outer (4)缺少1、3步骤,页面会闪烁 (5)点击箭头,内层“用动画”显示溢出区域,隐藏初始区域 <template> <div :style= "{visibility: isOuterShow ? 'visible':'hidden'}" > <div v- for = "(item,index) in allNote" :style= "{'background':item.readStatus?'#eaeef5':'#f5f6f9'}" class = "mynote" @click= "clickNoteItem(item)" :key= "index" > <div class = "mynote-item" > <div>{{item.title}}</div> <div> <span style= "padding-right: 30px;" >{{millsecondsToDate(item.receiveTime)}}</span> <el-icon :style= "{visibility: item.isShowArrow ? 'visible':'hidden'}" class = "cursor" > <ArrowRight style= "color: gray" v-show= "item.isFoldShow" @click.stop= "clickItemArrow(item)" /> <ArrowDown style= "color: gray" v-show= "!item.isFoldShow" @click.stop= "clickItemArrow(item)" /> </el-icon> </div> </div> <div v-show= "isFullShow" class = "isFullShow" >{{item.content}}</div> <div v-show= "item.isFoldShow" class = "fold_" >{{item.content}}</div> <!-- 下面, from -height,to-height(过程伴随overflow:hidden,应当与style-height一致) --> <div v-show= "!item.isFoldShow" : class = "!item.isFoldShow? 'divDown' + item.index:''" :style= "{'height':item.height + 'px','overflow':'hidden'}" >{{item.content}}</div> </div> </div> </template> <script setup> var isOuterShow = ref ( false ); //防止闪烁 var isFullShow = ref ( false ); //计算行高 var clickItemArrow = function(item){ item.isFoldShow = !item.isFoldShow; }; var getData = function(){ getAllNotes(data).then(function(result){ isFullShow.value = true ; allNote.length = 0; total.value = result.data.total; var list = result.data.list; for ( var i = 0; i<list.length; i++){ list[i].isShowArrow = false ; list[i].isFoldShow = false ; allNote.push(list[i]) } setTimeout(function(){ var all = document.getElementsByClassName( 'isFullShow' ) for ( var i = 0; i<all.length; i++){ if (all[i].clientHeight > 50) { allNote[i].isShowArrow = true ; allNote[i].isFoldShow = true ; allNote[i].index = i; allNote[i].height = all[i].clientHeight; document.styleSheets[0].insertRule( "@keyframes moveDown" + i + "{" + "from { height: 40px; }" + "to { height: " + all[i].clientHeight + "px; }" + "}" ) document.styleSheets[0].insertRule( ".divDown" + i + "{" + "animation: moveDown" + i + " 2s ease 0s 1 normal;" + /* 非常重要:2s前面有空格 */ "}" ) } } isFullShow.value = false ; isOuterShow.value = true ; }); }) }; onMounted(function() { getData(); }) </script> <style lang= "scss" > .cursor{ cursor: pointer; } .fold_{ overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; } </style> 4、元素底部出现,触发事件 (1)可演示 <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <meta name= "viewport" content= "width=device-width, initial-scale=1.0" > <title>元素底部出现,触发事件</title> <style> .div{ height: 500px; } #elementToTrack { height: 400px; background: gray; } </style> </head> <body> <div class = "div" ></div> <div class = "div" ></div> <div class = "div" ></div> <div id= "elementToTrack" ></div> <div class = "div" ></div> </body> <script> var element = document.getElementById( 'elementToTrack' ); window.onscroll = function() { var viewportHeight = window.innerHeight || document.documentElement.clientHeight; //获取视口的高度 var viewportBottom = window.scrollY + viewportHeight; //视口底部-到-页面顶部,距离 var elementBottom = element.offsetTop + element.offsetHeight; //元素底部-到-页面顶部,距离 if (viewportBottom > elementBottom) { //如果视口底部低于元素底部 console.log(viewportBottom, elementBottom); } }; </script> </html> (2)真实项目(表格底部消失在页面下面,左右滚动条出现在页面底部;表格底部出现,滚动条的位置恢复为默认的表格底部) //src/view/base/search-topical-table.vue;57--59;202--230;233 watch(() => props, (newVal) => { setTimeout(() => { checkScroll() },100) }, { immediate: true , deep: true }) var tableBody = null ; var container = null ; var isOver = ref ( false ) onMounted(() => { container = document.querySelector( '.main-container' ); tableBody = document.querySelector( '.el-table__body' ); container.addEventListener( 'scroll' , checkScroll); checkScroll(); }) onUnmounted(() => { container.removeEventListener( 'scroll' , checkScroll) }) function checkScroll() { // 获取目标元素的底部位置 var tableBottom = tableBody.getBoundingClientRect().bottom; var documentBottom = document.body.clientHeight; // 表格底部位于页面底部上方 if ( tableBottom < documentBottom ) { isOver.value = true ; } else { isOver.value = false ; } } <div class = "search-topical-table" : class = "{'search-topical-table-fixed':!isOver}" > <el-table></el-table> <el-pagination/> </div> <style lang= "scss" > .search-topical-table- fixed { .el-table__body-wrapper .el-scrollbar__bar. is -horizontal{ position: fixed ; bottom: 10px; left:165px; } } </style> (3)真实项目(滚动条的位置由默认的表格底部改为页面底部) <template> <div class = "search-topical-table" > <el-table></el-table> <el-pagination/> </div> </template> <style lang= "scss" > .search-topical-table{ .el-table__body-wrapper .el-scrollbar__bar. is -horizontal{ position: fixed ; bottom: 10px; height: 10px; } } </style> 5、在初始化时,滚动条回到顶部 (1)页面滚动条回到顶部 <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <title>页面滚动条回到顶部示例</title> <style> button { color: red; font-size: 50px; border-radius: 10px; position: fixed ; bottom: 0; right: 0; } .black { background: #000; color: #fff; } .div { height: 2000px; background-color: gray; } </style> </head> <body> <button id= "btn" >顶部--底部</button> <div class = "black" >顶部</div> <div class = "div" ></div> <div class = "black" >底部</div> </body> <script> var y = 0 ; var btn = document.getElementById( 'btn' ); btn.addEventListener( 'click' , function() { y = y == 0 ? 2000 : 0; window.scrollTo({ left: 0, top: y, behavior: 'smooth' }); }); </script> </html> (2)元素滚动条回到顶部 A、演示示例 <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <title>元素滚动条回到顶部示例</title> <style> button { color: red; font-size: 50px; border-radius: 10px; position: fixed ; top: 50px; right: 50px; } #myDiv { height: 500px; overflow: auto; } .black { background: #000; color: #fff; } #myDiv .myDiv { height: 1000px; background: gray; } </style> </head> <body> <button onclick= "clickBtn()" >顶部--底部</button> <div id= "myDiv" > <div class = "black" >顶部</div> <div class = "myDiv" ></div> <div class = "black" >底部</div> </div> </body> <script> var y = 0 ; function clickBtn() { y = y == 0? 1000 : 0; var div = document.getElementById( 'myDiv' ); div.scrollTo(0, y); } </script> </html> B、项目示例 .app-main { /*50 = navbar */ width: 100%; padding-bottom: 85px; margin-bottom: 20px; box-sizing: border-box; position: relative; //以下是,新增内容 overflow: auto; } method( params ).then(res => { allTableData.value = res.data.rows page.value.pageNum = res.data.pageNum page.value.pageSize = res.data.pageSize page.value.count = res.data.recordCount loading.value = false //以下是,新增内容 var height = window.innerHeight - 100 var ele = document.getElementsByClassName( 'app-main' )[0]; ele.style.height = height + 'px' ele.scrollTo({ top: 0, behavior: 'smooth' }) }) 6、在初始化时,(元素)滚动条回到底部 (1)html <div class = "training-result-code" > <div class = "training-result-title" > 训练日志 </div> <div class = "training-result-code_content1" ref = "divShow" > <div ref = "divSonShow" > {{ modelLogs }} </div> </div> <div class = "training-result-code_content2" ref = "divHide" > {{ modelLogs }} </div> </div> /* 以下弹窗中使用 */ <el-dialog title= "查看日志" v-model= "dialogVisible" width= "70%" > <div class = "record-detail-code" > <div class = "record-detail-code_content1" ref = "divShow" > <div ref = "divSonShow" > {{ modelLogs }} <div style= "padding-bottom: 100px" ></div> </div> </div> <div class = "training-result-code_content2" ref = "divHide" > {{ modelLogs }} </div> </div> <template #footer> <el-button type= "primary" @click= "dialogVisible = false" >确 定</el-button> </template> </el-dialog> (2)css &-code{ background-color: #fff; border-radius: 10px; height: 500px; padding: 30px; &_content1{ background-color: #000; overflow: scroll; color: #fff; white-space: pre-wrap; height: 420px; } &_content2{ background-color: #000; overflow: scroll; color: #fff; white-space: pre-wrap; visibility: hidden; } } /* 以下弹窗中使用 */ .record-detail-code{ background-color: #fff; border-radius: 10px; height: 500px; padding: 10px; overflow: hidden; &_content1{ background-color: #000; overflow: scroll; color: #fff; white-space: pre-wrap; height: 490px; } &_content2{ background-color: #000; overflow: hidden; color: #fff; white-space: pre-wrap; visibility: hidden; } } (3)js const modelLogs = ref ( '' ); const divShow = ref ( null ); const divSonShow = ref ( null ); const divHide = ref ( null ); const timerId = ref ( null ); const getLogs = function () { getModelTrainingLogs({trainingId: route.query.trainingId}).then(res => { modelLogs.value = res.data.runningLogs|| '没有训练日志' ; setTimeout(() => { divSonShow.value.style.height = divHide.value.clientHeight + 100 + 'px' ; divShow.value.scrollTop = divHide.value.clientHeight ; }); }) } getLogs() var textAry = [ '训练失败' , '训练完成' ]; if (textAry.indexOf(route.query.text) === -1){ timerId.value = setInterval(() => { getLogs() }, 500); } /* 以下弹窗中使用 */ const modelLogs = ref ( '' ); const divShow = ref ( null ); const divSonShow = ref ( null ); const divHide = ref ( null ); const showRecord = function(row){ dialogVisible.value = true ; getModelTrainingLogs({trainingId: row.trainingId}).then(res => { modelLogs.value = res.data.runningLogs|| '没有训练日志' ; setTimeout(() => { divSonShow.value.style.height = divHide.value.clientHeight + 'px' ; divShow.value.scrollTop = divHide.value.clientHeight*5 ; }); }) } 6、Vue.nextTick与任务队列 附、任务队列为空 来源,https: //www.ruanyifeng.com/blog/2014/10/event-loop.html A、所有的同步任务都在主线程的 "执行栈" 执行,所有的异步任务都放在 "任务队列" , B、主线程同步任务执行完毕,就会读取 "任务队列" 的异步任务,该任务离开 "任务队列" ,进入主线程的 "执行栈" 执行 C、主线程不断重复第2步,直到 "任务队列" 为空 (1)详细说明 来源,https: //blog.csdn.net/qq_39692513/article/details/123509911 A、同步执行, 数据A赋值,触发watcher,将异步事件推入到任务队列中;数据A再次赋值,不再触发,不再推入 nextTick-执行,将回调函数推入到任务队列中 B、异步执行, 主线程任务执行完毕,DOM更新,执行 "任务队列" , watch回调函数执行(会用到最终的数据A,但不能更改最终的数据A,以免陷入死循环) nextTick回调函数-执行(会用到更新后的DOM) 附、整个项目初始化时,存储相关回调函数,以备推入队列执行 (2)简略说明 A、主线程执行nextTick,回调函数推入 "任务队列" B、主线程任务执行完毕,DOM更新,执行 "任务队列" 的回调函数 (3)示例,来源,https: //blog.csdn.net/weixin_42333548/article/details/102606546 <template lang= "html" > <div id= "app" > <div id= "divBox" v- if = "showText" >测试文本内容</div> <button @click= "getText" >获取div内容</button> </div> </template> <script> export default { data () { return { showText: false } }, mounted () {}, methods: { getText () { this .showText = true ; this .$nextTick(() => { //加上这层壳,下面内容在DOM更新后执行 var innerHTML = document.getElementById( 'divBox' ).innerHTML; console.log(innerHTML); }) } }, } </script> <style lang= "less" ></style> 7、深度选择器 附、scoped说明 A、尽量不要使用scoped,原因:全局的样式名和本页面的样式名同名时,初次渲染,全局的样式名生效,后续浏览器刷新,本页面的样式名生效 B、替代方案,在本页面最外层用文件名作为样式名,如.app,.app .xxx (1)本页样式 >>> ,原生css支持,sass/less可能无法识别 <style scoped> .wrap >>> .child { color: red; } </style> (2)本页样式 /deep/ ,sass/less可识别,在vue 3.0会报错 <style scoped> .wrap /deep/ .child { color: red; } </style> (3)本页样式 ::v-deep ,vue 3.0支持,编译速度快 <style scoped> .wrap ::v-deep .child { color: red; } </style> (4)示例 <el-date-picker type= "date" v-model= "queryForm.finishDate" size= "small" format= "yyyy-MM-dd" placeholder= "请选择日期" ></el-date-picker> <style scoped lang= "scss" > ::v-deep .el-input--small .el-input__inner { height: 30px !important; line-height: 30px !important; } </style> <style scoped> .el-input--small .el-input__inner { height: 30px !important; line-height: 30px !important; } </style> (5)修改elementplus组件的原有样式 路径:右键页面元素-检查-右键标签-Copy-Copy outerHTML 使用:将上述复制结果粘贴到一个空文件里,看层级结构,写选择器 <style lang= "scss" > //为了解决bug:YANSHOU-10158,本页面此处不要加scoped 2022-2023获奖保密宣传视频合集 .el-upload-list__item-info>.el-progress>.el-progress__text>span{ //为了解决bug:http://10.70.38.84/browse/YANSHOU-10158 position: relative; left: 16px; bottom: 4px; } .channel- new -content-table{ margin-top: 20px; } .channel- new -el-upload__text{ padding-left: 10px; padding-bottom: 10px; } </style> 8、图片预览 (1)页面“有小图片占位的”预览 <el-image style= "width: 100px; height: 100px" :src= "url" :preview-src-list= "srcList" > </el-image> (2)页面“无小图片占位的”预览 <el-image-viewer @close= "imgVisible = false" :url-list= "[imgSrc]" v- if = "imgVisible" /> .el-image-viewer__canvas img{ //让图片显示为圆角且描白边 border-radius:10px; border:1px solid #fff } (3)图标-宽固定,高自适应 <svg-icon :icon- class = "scope.row.docType" style= "font-size: 24px" v-show= "scope.row.docType !== 'image'" /> <div style= "display: inline-block; width:24px" v-show= "scope.row.docType == 'image'" > <img :src= "scope.row.publicUrl" style= "width: 100%" /> </div> 9、拖拽 (1)半途而废案例(正在实现拖拽效果时,需求改变,遂停止) import Sortable from 'sortablejs' ; onMounted( function() { const tableBody = document.querySelector( '.el-table__body-wrapper tbody' ); new Sortable(tableBody, { animation: 150, onEnd: ( event ) => { const { oldIndex, newIndex } = event ; const draggedItem = tableData.value.splice(oldIndex, 1)[0]; tableData.value.splice(newIndex, 0, draggedItem); } }); }); (2)未测试案例(与row、col联合使用,模拟表格) <draggable class = "list-group" v-model= "tableData" :options= "{draggable:'.el-rows'}" :move= "getdata" @update= "datadragEnd" > <el-row class = "el-rows" v- for = "(item,index) in tableData" :key= "index" > <el-col span= "1" > <div class = "cell" >{{index+1}}</div> </el-col> <el-col span= "2" > <div class = "cell" >{{item.barCode}}</div> </el-col> <el-col span= "2" > <div class = "cell" >{{item.name}}</div> </el-col> <el-col span= "2" > <div class = "cell" >{{item.unit}}</div> </el-col> </el-row> </draggable> (3)不能用案例(与el-table联合使用,百度:vue-draggable、template与el-table联合使用的vue3用法示例) <script setup> import draggable from 'vuedraggable' ; const tableData = ref ( [ { id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Doe' } ]); const columns = ref ([ { label: 'ID' , prop: 'id' }, { label: 'Name' , prop: 'name' } ]); </script> <template> <div> <el-table :data= "tableData" style= "width: 100%" > <el-table-column v- for = "item in columns" :key= "item.prop" :prop= "item.prop" :label= "item.label" > </el-table-column> </el-table> <draggable v-model= "tableData" @end= "onDragEnd" > <template v-slot:item= "{ element }" > <div class = "draggable-item" >{{ element.name }}</div> </template> </draggable> </div> </template> (4)真实案例(与el-checkbox- group 联合使用,勾选) <script setup> import draggable from 'vuedraggable' const checkList = ref ([]) const columns = ref ([ { "label" : "序号" , "prop" : "processVersionSid" , "canChange" : false , "tip" : "数据示例:2346" }, { "label" : "栏目代码" , "prop" : "columnCode" , "canChange" : false , "tip" : "数据示例:J875023" }, { "label" : "详细情况说明" , "prop" : "reasonDetail" , "canChange" : true , "tip" : "数据示例:数据示例示例示例" }, { "label" : "系统备案栏目首播时间" , "prop" : "planPremiereTime" , "canChange" : true , "tip" : "数据示例:每周四 7:00 - 8:00" }, { "label" : "中心核对栏目首播信息" , "prop" : "checkPremiereTime" , "canChange" : true , "tip" : "数据示例:每周四 7:00 - 8:00" }, { "label" : "栏目重播信息" , "prop" : "replayTime" , "canChange" : true , "tip" : "数据示例:每周四 7:00 - 8:00" }, { "label" : "完成率" , "prop" : "completeRate" , "canChange" : true , "tip" : "数据示例:98%" }, { "label" : "备注" , "prop" : "remark" , "canChange" : false , "tip" : "" } ]) </script> <template> <div class = "column-select-warp" > <el-checkbox- group v-model= "checkList" > <draggable v-model= "columns" :force-fallback= "true" chosen- class = "chosen" draggable= ".drag" animation= "300" item-key= "prop" ><!-- draggable= ".drag" ,拖拽项的 class ; : class = "{'drag': element.canChange}" ,该项是否添加 class --> <template #item= "{ element, index }" > <div class = "column-select-item" : class = "{'drag': element.canChange}" > <svg-icon iconClass= "move" class = "move-icon" ></svg-icon> <el-checkbox :disabled= "!element.canChange" :value= "element.prop" size= "large" > <span>{{ element.label }}</span> <span class = "column-select-item__tip" >{{ element.tip }}</span> </el-checkbox> </div> </template> </draggable> </el-checkbox- group > </div> </template> (5)可运行案例(与table联合使用,可拖动表头栏和表体行) <!DOCTYPE html> <html> <head> <meta charset= "utf-8" /> <title>vue.draggable、表格、vue3联合示例</title> <meta name= "viewport" content= "width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui" > <script src= "https://www.itxst.com/package/vue3/vue.global.js" ></script> <script src= "https://www.itxst.com/package/sortable/Sortable.min.js" ></script> <script src= "https://www.itxst.com/package/vuedraggablenext/vuedraggable.umd.min.js" ></script> </head> <body style= "padding:10px;" > <div id= "app" > <itxst-component></itxst-component> </div> </body> <script type= "x-template" id= "itxst" > <div>教程,https: //www.itxst.com/vue-draggable-next/tutorial.html</div> <div>案例,https: //debug.itxst.com/js/zfzeny7f</div> <table class = "tb" > <thead> <draggable v-model= "headers" animation= "200" tag= "tr" :item-key= "(key) => key" > <template #item= "{ element: header, index: index}" > <th class = "move" > {{ header }} </th> </template> </draggable> </thead> <draggable :list= "list" handle= ".move" animation= "300" @start= "onStart" @end= "onEnd" tag= "tbody" item-key= "name" > <template #item= "{ element, index }" > <tr> <td class = "move" v- for = "(header, index) in headers" :key= "header" > {{ element[header] }} </td> </tr> </template> </draggable> </table> </script> <script> const app = { //注册draggable组件 components: { 'itxst-component' : { template: "#itxst" , components: { "draggable" : window.vuedraggable, }, data() { return { //列的名称 headers: [ "id" , "name" , "intro" ], //需要拖拽的数据,拖拽后数据的顺序也会变化 list: [ { name: "www.itxst.com" , id: 0, intro: "慢吞吞的蜗牛" }, { name: "www.baidu.com" , id: 1, intro: "中文搜索引擎" }, { name: "www.google.com" , id: 3, intro: "安卓操作系统" }, ], } }, methods: { //开始拖拽事件 onStart() {}, //结束拖拽事件 onEnd() {} } } }, } Vue.createApp(app).mount( '#app' ) </script> <style> .title { padding: 3px; font-size: 13px; } .itxst { width: 600px; } .move { cursor: move; } table.tb { color: #333; border: solid 1px #999; font-size: 13px; border-collapse: collapse; min-width: 500px; user- select : none; } table.tb th { background: rgb(168 173 217); border-width: 1px; padding: 8px; border-style: solid; border-color: #999; text-align: left; } table.tb th:nth-of-type(1) { text-align: center; } table.tb td { background: #d6c8c8; border-width: 1px; padding: 8px; border-style: solid; border-color: #999; } table.tb td:nth-of-type(1) { text-align: center; } </style> </html> (6)可运行案例(与vue3联合使用,无序列表) <!DOCTYPE html> <html> <head> <meta charset= "utf-8" /> <title>vue.draggable、无序列表、vue3联合示例</title> <meta name= "viewport" content= "width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui" > <script src= "https://www.itxst.com/package/vue3/vue.global.js" ></script> <script src= "https://www.itxst.com/package/sortable/Sortable.min.js" ></script> <script src= "https://www.itxst.com/package/vuedraggablenext/vuedraggable.umd.min.js" ></script> </head> <body> <div id= "app" > <div class = "itxst" > <div class = "group" > <draggable :list= "modules.group1" group = "group1" handle= ".move" filter= ".forbid" @start= "onStart" @end= "onEnd" :move= "onMove" ghost- class = "ghost" chosen- class = "chosenClass" animation= "300" :force-fallback= "true" :touch-start-threshold= "50" :fallback- class = "true" :fallback- on -body= "true" :fallback-tolerance= "50" > <template #item= "{ element, index }" > <div : class = "element.disabledMove ? 'forbid item' : 'item'" > <label class = "move" >{{ element.name }}</label> <p v-show= "element.disabledPark" style= "color:red" >此处不允许拖拽和停靠</p> <p v-show= "!element.disabledPark" >内容......</p> </div> </template> </draggable> </div> <div class = "group" > <draggable :list= "modules.group2" group = "group1" handle= ".move" filter= ".forbid" @start= "onStart" @end= "onEnd" :move= "onMove" ghost- class = "ghost" chosen- class = "chosenClass" animation= "300" :force-fallback= "true" :touch-start-threshold= "50" :fallback- class = "true" :fallback- on -body= "true" :fallback-tolerance= "50" > <template #item= "{ element, index }" > <div : class = "element.disabledMove ? 'forbid item' : 'item'" > <label class = "move" >{{ element.name }}</label> <p>内容....</p> </div> </template> </draggable> </div> <div class = "group" > <draggable :list= "modules.group3" group = "group1" handle= ".move" filter= ".forbid" @start= "onStart" @end= "onEnd" :move= "onMove" ghost- class = "ghost" chosen- class = "chosenClass" animation= "300" :force-fallback= "true" :touch-start-threshold= "50" :fallback- class = "true" :fallback- on -body= "true" :fallback-tolerance= "50" > <template #item= "{ element, index }" > <div : class = "element.disabledMove ? 'forbid item' : 'item'" > <label class = "move" >{{ element.name }}</label> <p>内容....</p> </div> </template> </draggable> </div> </div> <div> <div>教程,https: //www.itxst.com/vue-draggable-next/tutorial.html</div> <div>案例,https: //debug.itxst.com/js/byamn2ja</div> <div>属性说明:</div> <div style= "display: flex;" > <pre> animation:拖动时过渡动画持续时间 chosen- class :选中的样式 disabled:是否禁用拖拽组件 delay:鼠标按下多少秒之后可以拖拽元素 drag- class :拖动元素的样式 draggable:通过样式设置拖拽,:draggable= ".item" ,样式类为item的元素才能被拖动 fallback- class :克隆选中元素的样式到跟随鼠标的样式 fallback- on -body:克隆的元素添加到文档的body中 fallback-tolerance:按下鼠标移动多少个像素才能拖动元素 filter:通过样式设置不拖拽,:filter= ".unmover" ,设置了unmover样式的元素不允许拖动 force-fallback:忽略HTML5的拖拽行为 ghost- class :宿主样式 group :相同的组名可以相互拖拽 handle:通过样式设置拖拽,:handle= ".mover" ,只有当鼠标在样式类为mover类的元素上才能触发拖动 </pre> <pre> list:数据源 scroll:有滚动区域是否允许拖拽 scroll-fensitivity:距离滚动区域多远时,滚动滚动条 scroll-fn:滚动回调函数 scroll-speed:滚动速度 sort:是否开启排序 touch-start-threshold:鼠标按下移动多少px才能拖动元素交换间隔的大小,可以查看菜单对应的属性说明 @start:开始拖拽事件 :move:拖拽中事件,可以用来控制是否允许停靠 @end:结束拖拽事件 vue-draggable组件的disabled、filter、handle、draggable这几个属性,优先级从高到低的排序是什么 disabled > handle > draggable(也可配置在插槽中) > filter </pre> </div> </div> </div> <script> const app = { data() { return { modules: { group1: [ { name: "第1组-1" , id: 1, disabledMove: true , disabledPark: true }, { name: "第1组-2" , id: 2, disabledMove: false , disabledPark: false }, { name: "第1组-3" , id: 3, disabledMove: false , disabledPark: false }, ], group2: [ { name: "第2组-1" , id: 5, disabledMove: false , disabledPark: false }, { name: "第2组-2" , id: 6, disabledMove: false , disabledPark: false }, { name: "第2组-3" , id: 7, disabledMove: false , disabledPark: false }, ], group3: [ { name: "第3组-1" , id: 8, disabledMove: false , disabledPark: false }, { name: "第3组-2" , id: 9, disabledMove: false , disabledPark: false }, ], }, } }, //注册draggable组件 components: { 'draggable' : window.vuedraggable }, methods: { //拖拽开始的事件 onStart() { console.log( "开始拖拽" ); }, //拖拽结束的事件 onEnd() { console.log( "结束拖拽" ); }, onMove(e) { //不允许停靠 if (e.relatedContext.element.disabledPark == true ) return false ; return true ; } } } Vue.createApp(app).mount( '#app' ) </script> <style> body { padding: 0px; margin: 0px; background-color: #f1f1f1; } .itxst { background-color: #f1f1f1; display: flex; justify-content: space-between; align-content: space-around; padding: 20px; } . group { display: flex; flex-direction: column; justify-content: flex-start; align-content: center; width: 32%; } .item { border: solid 1px #ddd; padding: 0px; text-align: left; background-color: #fff; margin-bottom: 10px; display: flex; flex-direction: column; height: 100px; user- select : none; } .item>label { border-bottom: solid 1px #ddd; padding: 6px 10px; color: #333; } .item>label:hover { cursor: move; } .item>p { padding: 0 10px; color: #666; } .ghost { border: solid 1px rgb(19, 41, 239) !important; } .chosenClass { opacity: 1; border: solid 1px red; } .fallbackClass { background-color: aquamarine; } </style> </body> </html> 10、 select 多选时,先选中的在前,后选中的在后 <template> <el-form :model= "filterForm" label-width= "90px" label-position= "left" > <el-form-item label= "中心" > <el- select v-model= "filterForm.center" style= "width: 220px;" multiple collapse-tags collapse-tags-tooltip clearable placeholder= "全部" @change= "changeCenter" > <el-option v- for = "item in centerOptions" :key= "item.id" :label= "item.name" :value= "item.id" /> </el- select > </el-form-item> <div class = "search-organize-three" > <div> <el-form-item label= "传播渠道" > <el- select v-model= "filterForm.channel" @change= "changeChannel" style= "width: 220px;" multiple collapse-tags collapse-tags-tooltip clearable placeholder= "请选择" > <el-option v- for = "item in spreadChannel" :key= "item.id" :label= "item.name" :value= "item.id" /> </el- select > </el-form-item> </div> <div @click= "clickExpandOrCollapse" class = "div-three" > <span v-show= "!isExpand" >展开<el-icon><ArrowDown/></el-icon></span> <span v-show= "isExpand" >收起<el-icon><ArrowUp/></el-icon></span> </div> </div> <div v-show= "isExpand && filterForm.channel.length>0" class = "search-organize-detail" > <!-- 以下写法,是为了先选中的在前,后选中的在后 --> <el-row v- for = "(item,index) in Array(Math.ceil(filterForm.channel.length/num))" :key= "item" > <el-col :span= "6" v- for = "(itemIn, indexIn) in Array(num)" :key= "itemIn" > <el-form-item :label= "spreadChannel[0].name" v-show= "filterForm.channel.indexOf(spreadChannel[0].id) == num*index+indexIn" > <el- select v-model= "spreadChannel[0].model" class = "search-organize-width-margin" placeholder= "请选择" @change= "changeSelect" multiple :clearable= "true" > <el-option v- for = "item in TVChannelOptions" :key= "item.channelCode" :label= "item.channelName" :value= "item.channelCode" /> </el- select > </el-form-item> <el-form-item :label= "spreadChannel[1].name" v-show= "filterForm.channel.indexOf(spreadChannel[1].id) == num*index+indexIn" > <el- select v-model= "spreadChannel[1].model" class = "search-organize-width-margin" filterable remote reserve-keyword placeholder= "请输入对内广播名称" :remote-method= "remoteRadioList" :loading= "radioLoading" > <el-option v- for = "item in innerRadioOptions" :key= "item.columnId" :label= "item.freqName" :value= "item.columnId" > <span style= "float: left" >{{ item.freqName }}</span> <span style=" float : right; color: var (--el-text-color-secondary); font-size: 13px; " > {{ item.columnId }} </span> </el-option> </el- select > </el-form-item> <el-form-item :label= "spreadChannel[2].name" v-show= "filterForm.channel.indexOf(spreadChannel[2].id) == num*index+indexIn" > <el- select v-model= "spreadChannel[2].model" class = "search-organize-width-margin" placeholder= "请选择" @change= "changeSelect" > <el-option v- for = "item in spreadChannel[2].childrens" :key= "item.id" :label= "item.name" :value= "item.id" /> </el- select > </el-form-item> <el-form-item :label= "spreadChannel[3].name" v-show= "filterForm.channel.indexOf(spreadChannel[3].id) == num*index+indexIn" > <el- select v-model= "spreadChannel[3].model" class = "search-organize-width-margin" placeholder= "请选择" @change= "changeSelect" > <el-option v- for = "item in spreadChannel[3].childrens" :key= "item.id" :label= "item.name" :value= "item.id" /> </el- select > </el-form-item> <!-- 以下,4个 --> <el-form-item :label= "spreadChannel[4].name" v-show= "filterForm.channel.indexOf(spreadChannel[4].id) == num*index+indexIn" > <el- select v-model= "spreadChannel[4].model" class = "search-organize-width-margin" placeholder= "请选择" @change= "changeSelect" > <el-option v- for = "item in spreadChannel[4].childrens" :key= "item.id" :label= "item.name" :value= "item.id" /> </el- select > </el-form-item> <el-form-item :label= "spreadChannel[5].name" v-show= "filterForm.channel.indexOf(spreadChannel[5].id) == num*index+indexIn" > <el- select v-model= "spreadChannel[5].model" class = "search-organize-width-margin" placeholder= "请选择" @change= "changeSelect" > <el-option v- for = "item in spreadChannel[5].childrens" :key= "item.id" :label= "item.name" :value= "item.id" /> </el- select > </el-form-item> <el-form-item :label= "spreadChannel[6].name" v-show= "filterForm.channel.indexOf(spreadChannel[6].id) == num*index+indexIn" > <el- select v-model= "spreadChannel[6].model" class = "search-organize-width-margin" placeholder= "请选择" @change= "changeSelect" > <el-option v- for = "item in spreadChannel[6].childrens" :key= "item.id" :label= "item.name" :value= "item.id" /> </el- select > </el-form-item> <el-form-item :label= "spreadChannel[7].name" v-show= "filterForm.channel.indexOf(spreadChannel[7].id) == num*index+indexIn" > <el- select v-model= "spreadChannel[7].model" class = "search-organize-width-margin" placeholder= "请选择" @change= "changeSelect" > <el-option v- for = "item in spreadChannel[7].childrens" :key= "item.id" :label= "item.name" :value= "item.id" /> </el- select > </el-form-item> </el-col> </el-row> </div> <div class = "search-organize-date" > <el-form-item label= "选择日期" > <el-date-picker v-model= "filterForm.date" type= "daterange" value-format= "YYYY-MM-DD" range-separator= "—" :shortcuts= "date_shortcuts" start-placeholder= "开始日期" end-placeholder= "结束日期" /> </el-form-item> </div> <div class = "search-organize-button" > <div> <el-button v- for = "(item, index) in operateList" :key= "index" @click= "clickThreeButton(index)" : class = "operateIndex == index ? 'active-button' : ''" > {{ item.title }} </el-button> </div> </div> </el-form> </template> <script setup> const num = 2; //每行显示项数 const isExpand = ref ( false ) //以下,传播渠道及其子选项的获取 const spreadChannel = ref ([]) //传播渠道及其子选项 getAllChannel({ m_LIKE_code: "zh_" , level:1 }).then(res => { var all = res.data; var firstChildrens = all[0].childrens; firstChildrens.forEach((itemUp, indexUp) => { all.forEach((itemDown, indexDown) => { if ( indexDown > 1 && itemUp.name == itemDown.name) { var array = [ '对外广播' , 'APP' , '网站' , '国内社媒' , '海外社媒' , 'OTT' ]; itemUp.childrens = itemDown.childrens itemUp.model = '' if (array.indexOf(itemUp.name) != -1) { itemUp.childrens.unshift({ name: '全部' , id: '全部' }) } } }); }); spreadChannel.value = firstChildrens }) </script> |
« 上一篇: 10、Vue之#app|v-简写|key|$refs实例和组件异同'@'滚动加载set、内置组件、组件传值传参可演示、组件七种写法、插槽slot后备、vue2源码、vue2和vue3区别生命周期setup、vuex|pinia、vue-router(权限)、vue-cli|vue.config.js|跨域proxy代理、mock(3600行)
» 下一篇: 12、React之分页组件(含勾选、过滤、表头纵横合并、子组件向父组件传值)、redux、redux-thunk、react-router、react-redux、React基础|版本与优化、Hook钩子、组件写法、插槽、Model多层弹窗组件、react.15.6源码、ant-design-pro构成、Vue与React的异同(2800行)
» 下一篇: 12、React之分页组件(含勾选、过滤、表头纵横合并、子组件向父组件传值)、redux、redux-thunk、react-router、react-redux、React基础|版本与优化、Hook钩子、组件写法、插槽、Model多层弹窗组件、react.15.6源码、ant-design-pro构成、Vue与React的异同(2800行)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理