반응형
vuejs 구성 요소의 사용자 php captcha
Larabel 5.4.20 및 VueJs에서modal 컴포넌트에 심플한 코드 captcha를 사용하고 싶다(reCaptcha를 사용하고 싶지 않다).이거 어떻게 해?
Mewebstudio Captcha를 이렇게 사용하고 있습니다.
Route::any('captcha-test', function()
{
if (Request::getMethod() == 'POST')
{
$rules = ['captcha' => 'required|captcha'];
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
echo '<p style="color: #ff0000;">Incorrect!</p>';
}
else
{
echo '<p style="color: #00ff30;">Matched :)</p>';
}
}
$form = '<form method="post" action="captcha-test">';
$form .= '<input type="hidden" name="_token" value="' . csrf_token() . '">';
$form .= '<p>' . captcha_img() . '</p>';
$form .= '<p><input type="text" name="captcha"></p>';
$form .= '<p><button type="submit" name="check">Check</button></p>';
$form .= '</form>';
return $form;
});
다만, PHP 문서에서는 동작합니다(Vue 컴포넌트에 필요합니다).
이를 실현하기 위해route
다음과 같습니다.
Route::post('captcha-test', function() {
$validator = Validator::make(Input::all(), [
'captcha' => 'required|captcha'
])->validate();
return response(['status' => 'ok'], 200);
});
Vue 컴포넌트는 다음과 같습니다.
Vue.component('captcha', {
props: ['image'],
data: function () {
return {
form: {
captcha: null
},
isWorking: false
}
},
methods: {
check: function () {
var self = this
self.isWorking = true
axios.post('/captcha-test', {
captcha: self.form.captcha
})
.then(function (response) {
// valid captcha...
console.log(response);
// reset the form
self.form.captcha = null
// now, is not working
self.isWorking = false
})
.catch(function (err) {
// invalid captch..
console.log(err);
// reset the form
self.form.captcha = null
// now, is not working
self.isWorking = false
});
}
}
});
new Vue({
el: '#app'
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.16.2/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.5.1/css/bulma.css" rel="stylesheet"/>
<div id="app" class="section">
<captcha image="<img src='https://c22blog.files.wordpress.com/2010/10/input-black.gif' style='width: 150px;'>" inline-template>
<div class="box">
<div v-html="image"></div>
<form @submit.prevent="check">
<div class="field">
<div class="control">
<input class="input" type="text" placeholder="Captcha" v-model="form.captcha" required>
</div>
</div>
<div class="field">
<div class="control">
<button type="submit" class="button is-primary" :class="{'is-loading': isWorking}" :disabled="isWorking">Check</button>
</div>
</div>
</form>
</div>
</captcha>
</div>
언급URL : https://stackoverflow.com/questions/45759425/user-php-captcha-in-vuejs-component
반응형
'programing' 카테고리의 다른 글
하나의 커스텀 npm 패키지로 Vue 및 Vuex 내보내기 (0) | 2022.07.10 |
---|---|
asm, asm volatile 및 clobbering 메모리의 차이 (0) | 2022.07.10 |
프로토콜에 초기화 기능을 사용할 수 있습니까? (0) | 2021.01.18 |
WildFly에서 기본 포트 8080을 변경하는 방법 (0) | 2021.01.18 |
도커 이미지의 sha256 코드는 어디에서 찾을 수 있습니까? (0) | 2021.01.18 |