ChingFeng
Sep 9, 2018 · 2 min read

VueJs Ajax篇-Axios(七)

過濾字串

◉應用-過濾指定輸入字串

=【Html】=
— — — — — — — — — — — —
<div id="app">
<h3>Who's better: Socrats or Plato?</h3>
<p>Technically, without Plato we wouldn't have<br> much to go on when it comes to innformation about<br>Socrates. Plato ftw!</p>
<form>
<label>Write your comment:</label>
<textarea v-model="message"></textarea>
<button @click.prevent="submit">Send</button>
</form>
<p>Sever got: {{response}}</p>
</div>
— — — — — — — — — — — —
=【VueJs】=
— — — — — — — — — — — —
new Vue({
el: '#app',
data:{
message: '',
response: '...'
},
methods:{
submit(){
axios.post('http://jsonplaceholder.typicode.com/comments',{
body: this.message
}).then(response => {
this.response = response.data;
})
}
},
mounted(){
axios.interceptors.request.use(config => {
const body = config.data.body.replace(/punk/i, '***');
config.data.body = body;
return config;
});
}
});

Object實戰

學習歷程紀錄

ChingFeng

Written by

叢林般的世界,一步步邁向未知的未來,迴盪迷途的工程師…

Object實戰

學習歷程紀錄

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade