vue-addresstw-my
Version:
A Vue component for select Taiwan county, city and zipcode.
293 lines (243 loc) • 10.4 kB
JavaScript
/******/ (function() { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ 89:
/***/ (function(__unused_webpack_module, exports) {
;
var __webpack_unused_export__;
__webpack_unused_export__ = ({
value: true
}); // runtime helper for setting properties on components
// in a tree-shakable way
exports.Z = (sfc, props) => {
const target = sfc.__vccOpts || sfc;
for (const [key, val] of props) {
target[key] = val;
}
return target;
};
/***/ }),
/***/ 325:
/***/ (function() {
// import twzipcode from 'twzipcode-data'
// let data = twzipcode()
//
// export const counties = data.counties.map(county => county.name)
// export const zipcodes = data.zipcodes.map(zipcode => {
// return {
// zipcode: zipcode.id,
// county: zipcode.county,
// city: zipcode.city
// }
// })
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ !function() {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = function(exports, definition) {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ !function() {
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ }();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ !function() {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/publicPath */
/******/ !function() {
/******/ __webpack_require__.p = "";
/******/ }();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
!function() {
;
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
"default": function() { return /* binding */ entry_lib; }
});
;// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js
/* eslint-disable no-var */
// This file is imported into lib/wc client bundles.
if (typeof window !== 'undefined') {
var currentScript = window.document.currentScript
if (false) { var getCurrentScript; }
var src = currentScript && currentScript.src.match(/(.+\/)[^/]+\.js(\?.*)?$/)
if (src) {
__webpack_require__.p = src[1] // eslint-disable-line
}
}
// Indicate to webpack that this file can be concatenated
/* harmony default export */ var setPublicPath = (null);
;// CONCATENATED MODULE: external {"commonjs":"vue","commonjs2":"vue","root":"Vue"}
var external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject = require("vue");
;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/vue-loader/dist/templateLoader.js??ruleSet[1].rules[3]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/components/zipCode.vue?vue&type=template&id=c45593fc
const _hoisted_1 = {
class: "vue-address"
};
const _hoisted_2 = ["name"];
const _hoisted_3 = /*#__PURE__*/(0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementVNode)("option", {
value: "",
disabled: ""
}, "請選擇", -1);
const _hoisted_4 = ["value"];
const _hoisted_5 = ["name"];
const _hoisted_6 = /*#__PURE__*/(0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementVNode)("option", {
value: "",
disabled: ""
}, "請選擇", -1);
const _hoisted_7 = ["value"];
function render(_ctx, _cache, $props, $setup, $data, $options) {
return (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.openBlock)(), (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementBlock)("div", _hoisted_1, [(0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.withDirectives)((0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementVNode)("select", {
name: $props.name,
"onUpdate:modelValue": _cache[0] || (_cache[0] = $event => $data.countyValue = $event),
id: ""
}, [_hoisted_3, ((0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.openBlock)(true), (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementBlock)(external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.Fragment, null, (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.renderList)($data.counties, county => {
return (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.openBlock)(), (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementBlock)("option", {
key: county,
value: county
}, (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.toDisplayString)(county), 9, _hoisted_4);
}), 128))], 8, _hoisted_2), [[external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.vModelSelect, $data.countyValue]]), (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.withDirectives)((0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementVNode)("select", {
name: $props.name,
"onUpdate:modelValue": _cache[1] || (_cache[1] = $event => $data.cityValue = $event),
id: ""
}, [_hoisted_6, ((0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.openBlock)(true), (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementBlock)(external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.Fragment, null, (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.renderList)($data.counties, city => {
return (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.openBlock)(), (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.createElementBlock)("option", {
key: city,
value: city
}, (0,external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.toDisplayString)(city), 9, _hoisted_7);
}), 128))], 8, _hoisted_5), [[external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.vModelSelect, $data.cityValue]])]);
}
;// CONCATENATED MODULE: ./src/components/zipCode.vue?vue&type=template&id=c45593fc
// EXTERNAL MODULE: ./src/utils/index.js
var utils = __webpack_require__(325);
;// CONCATENATED MODULE: ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/components/zipCode.vue?vue&type=script&lang=js
/* harmony default export */ var zipCodevue_type_script_lang_js = ({
props: {
name: {
type: String,
default: 'county'
},
defaultFirst: {
type: Boolean,
default: false
},
city: {
type: String,
default: ''
},
county: {
type: String,
default: ''
}
},
watch: {
countyValue() {
if (this.defaultFirst) {
this.cityValue = this.cities[0];
}
this.handleChange();
},
cityValue() {
this.handleChange();
}
},
data() {
return {
counties: utils.counties,
countyValue: '',
cityValue: ''
};
},
computed: {
cities() {
if (!this.countyValue) {
return [];
}
return utils.zipcodes.filter(zipcode => zipcode.county === this.countyValue).map(zipcode => zipcode.city);
},
zipcodeValue() {
return utils.zipcodes.filter(zipcode => zipcode.county === this.countyValue).find(zipcode => zipcode.city === this.cityValue).zipcode;
}
},
created() {
this.countyValue = this.county;
this.cityValue = this.city;
if (this.defaultFirst && !this.county) {
this.countyValue = utils.counties[0];
}
},
methods: {
handleChange() {
this.$emit('change', {
county: this.countyValue,
city: this.cityValue,
zipcode: this.zipcodeValue
});
}
}
});
;// CONCATENATED MODULE: ./src/components/zipCode.vue?vue&type=script&lang=js
// EXTERNAL MODULE: ./node_modules/vue-loader/dist/exportHelper.js
var exportHelper = __webpack_require__(89);
;// CONCATENATED MODULE: ./src/components/zipCode.vue
;
const __exports__ = /*#__PURE__*/(0,exportHelper/* default */.Z)(zipCodevue_type_script_lang_js, [['render',render]])
/* harmony default export */ var zipCode = (__exports__);
;// CONCATENATED MODULE: ./src/components/index.js
zipCode.install = function (Vue) {
Vue.component('vue-address', zipCode);
};
/* harmony default export */ var components = (zipCode);
;// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/entry-lib.js
/* harmony default export */ var entry_lib = (components);
}();
module.exports = __webpack_exports__;
/******/ })()
;
//# sourceMappingURL=vue-address.common.js.map