I’m learning vue. js .I’m trying to make simple form by using vue.js but I got above error while making a form. I tried but unable to fix the problem. Please help me.
JavaScript
x
38
38
1
<div id="app">
2
<form name="form" @submit.prevent="handleLogin">
3
<input
4
v-model="fiscal_year"
5
v-validate="'required'"
6
type="text"
7
class="form-control"
8
name="fiscal_year"
9
/>
10
<button class="btn btn-primary btn-block" :disabled="loading">
11
<span v-show="loading" class="spinner-border spinner-border-sm"></span>
12
<span>Submit</span>
13
</button>
14
</form>
15
16
<script>
17
var app = new Vue({
18
el: '#app',
19
20
data: {
21
fiscal_year: 2000,
22
loading: false,
23
},
24
mount:function(){},
25
methods: {
26
handleLogin(){
27
28
console.log('handle login');
29
this.loading = true;
30
}
31
32
}
33
})
34
</script>
35
36
37
38
Advertisement
Answer
UPDATE
If you are using cli-vue : https://cli.vuejs.org/
Assume you put file in App.vue
:
JavaScript
1
30
30
1
<template>
2
<div id="app">
3
<h1>hello</h1>
4
<form name="form" @submit.prevent="handleLogin">
5
<input v-model="fiscal_year" type="text" class="form-control" name="fiscal_year">
6
<button class="btn btn-primary btn-block" :disabled="loading">
7
<span v-show="loading" class="spinner-border spinner-border-sm"></span>
8
<span>Submit</span>
9
</button>
10
</form>
11
</div>
12
</template>
13
14
<script>
15
export default {
16
data() {
17
return {
18
fiscal_year: 2000,
19
loading: false
20
};
21
},
22
methods: {
23
handleLogin() {
24
console.log("handle login");
25
this.loading = true;
26
}
27
}
28
};
29
</script>
30
Dont use jquery in Vue project. If you want to use bootstrap you can use bootsrap-vue
: https://bootstrap-vue.js.org/
But if you are using vue in html use this : https://v2.vuejs.org/v2/guide/
— Previous —
First, have you read vuejs introduction in https://v2.vuejs.org/v2/guide/ and Vue Lesson on Scrimba ?
About the question. <template>
are used in component. You can replace it to <div id="app">
:
JavaScript
1
25
25
1
<div id="app"> <!-- Replace <template> with <div> -->
2
<div class="col-md-12">
3
<form name="form" @submit.prevent="handleLogin">
4
<div class="form-group col-md-6">
5
<label for="fiscal_year">Fiscal Year</label>
6
<input
7
v-model="fiscal_year"
8
v-validate="'required'"
9
type="text"
10
class="form-control"
11
name="fiscal_year"
12
/>
13
</div>
14
15
<div class="form-group">
16
<button class="btn btn-primary btn-block" :disabled="loading">
17
<span v-show="loading" class="spinner-border spinner-border-sm"></span>
18
<span>Submit</span>
19
</button>
20
</div>
21
22
</form>
23
</div>
24
</div>
25
Then you create vue instance in the <script>
tag :
JavaScript
1
14
14
1
var app = new Vue({
2
el: '#app',
3
4
data: {
5
fiscal_year: 2000,
6
loading: false,
7
},
8
methods: {
9
handleLogin(){
10
console.log('handle login');
11
this.loading = true;
12
}
13
}
14