SOURCE

console 命令行工具 X clear

                    
>
console
let app = new Vue({
	el: '#app',
  data: {
  	location: '',
    zipcode: ''
  },
  watch: {
  	zipcode: function() {
    	this.lookup();
    }
  },
  methods: {
  	lookup: function() {
    	this.location = '';
      if ( this.zipcode.length == 5 ) {
      	setTimeout (() => {
        	this.location = 'Searching...';
          axios.get ('https://ziptasticapi.com/' + this.zipcode)
          		 .then ((response) => {
               		if ( this.zipcode.length !== 5 ) {
                    this.location = '';
                    return;
                  }
               		let res = response.data;
                  if (res.city == undefined) {
                  	this.location = 'Invalid Zipcode';
                    return;
                  }
               		this.location = res.city + ', ' + res.state;
               })
        }, 500);
      }
    }
  }
});
<div id="app">
  ZIPcode: <input type="text" v-model="zipcode"> <br>
  <span> {{ location }} </span>
</div>

本项目引用的自定义外部资源