2017-11-03 1 views
0

Vue 앱을 만들고 있습니다. 폼의 버튼을 클릭하면 값이 paypal 인 입력을 채우고 양식을 제출합니다. 그러나 test_form.php (양식의 파일 작업)에서 $_POST['paymentMethod'] 변수는 paypal 대신 null을 포함합니다! 내가 틀린 곳?Vue에서 필드를 채운 후에 폼을 제출하는 것

HTML :

<form action="test/test_form.php" method="POST" ref="form"> 
    <button type="button" v-on:click="setMethod('cc')">Credit card</button> 
    <button type="button" v-on:click="setMethod('paypal')">Paypal</button> 
    <input type="text" name="paymentMethod" required v-model="selectedMethod"> 
</form> 

자바 스크립트 :

new Vue({ 
    el: "#app", 

    data: { 
    selectedMethod: null, 
    }, 

    methods: { 

    // Set payment 
    setMethod: function(type) { 
     this.selectedMethod = type; // Here I fill the field 
     this.$refs.form.submit(); // Then I submit the form 
    }, 
    } 

}); 

답변

2

양식 게시물을 연기 할 뷰의 nextTick 방법을 사용해보십시오 까지을 한 후 여기에

내가 사용하고 코드입니다 DOM이 업데이트되었습니다 :

if (type == 'paypal'){ 
    var me = this; 
    Vue.nextTick(function() { 
     me.$refs.form.submit(); 
    }; 
    } 
+0

방금 ​​readonly 특성을 제거했지만 문제가 지속됩니다. 질문을 좀 더 명확하게 업데이트했습니다. –

+0

'nextTick' 사용에 대한 답변을 볼 수 있습니다. – PatrickSteele

+0

감사합니다 패트릭! 내가 틀렸기 때문에 답의 첫 부분을 제거하는 것이 좋습니다 => https://stackoverflow.com/a/16438237/1252920 –

관련 문제