DevLog
Python, TypeScript, etc...
MyPage
Python, TypeScript, etc...
2022/07/22

yubinbango-core2を使ってVue.jsで郵便番号から住所を自動入力する

Vue.js
preview
@shiromisanta
Frontend Engineer
  •  /
目次
Install

Install

yubinbango-core2を使います。

https://www.npmjs.com/package/yubinbango-core2

npm install yubinbango-core2

使い方

<template> <input type="text" v-model="zipcode" placeholder="郵便番号"/> </template> <script lang="ts"> import Vue from 'vue' import YubinBango from 'yubinbango-core2' type AddressByYubinBango = { 'region_id': number, region: string, locality: string, street: string, extended: string, } export default Vue.extend({ data() { return { info: { zipcode: '', prefecture: '', city: '', } } }, computed: { zipcode: { get(): string { return this.info.zipcode }, set(zipcode: string) { this.info = {...this.info, zipcode} if (zipcode.length === 7) { const self = this const _ = new YubinBango.Core(zipcode, function (address: AddressByYubinBango) { self.info = { ...this.info, prefecture: address.region, city: address.locality + address.street } }) } } }, } }) </script>

関連記事

preview
@shiromisanta 2022/06/12
Nuxt.jsVue.js
preview
@shiromisanta 2022/01/11
vee-validateVue.jsNuxt.js
2022/07/22

yubinbango-core2を使ってVue.jsで郵便番号から住所を自動入力する

Vue.js

Install

yubinbango-core2を使います。

https://www.npmjs.com/package/yubinbango-core2

npm install yubinbango-core2

使い方

<template> <input type="text" v-model="zipcode" placeholder="郵便番号"/> </template> <script lang="ts"> import Vue from 'vue' import YubinBango from 'yubinbango-core2' type AddressByYubinBango = { 'region_id': number, region: string, locality: string, street: string, extended: string, } export default Vue.extend({ data() { return { info: { zipcode: '', prefecture: '', city: '', } } }, computed: { zipcode: { get(): string { return this.info.zipcode }, set(zipcode: string) { this.info = {...this.info, zipcode} if (zipcode.length === 7) { const self = this const _ = new YubinBango.Core(zipcode, function (address: AddressByYubinBango) { self.info = { ...this.info, prefecture: address.region, city: address.locality + address.street } }) } } }, } }) </script>

関連記事

preview
@shiromisanta
Frontend Engineer
  •  /
©︎Devlog