Skip to content

Commit

Permalink
Note 组件,v-model
Browse files Browse the repository at this point in the history
  • Loading branch information
mcxue committed May 21, 2020
1 parent 4e6c619 commit 3c646d0
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 43 deletions.
13 changes: 8 additions & 5 deletions src/components/Account/Choice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
<div>类别</div>
<ul>
<li class="selected">默认</li>
<li>衣</li>
<li>食</li>
<li>住</li>
<li>行</li>
</ul>
</div>

Expand All @@ -15,8 +11,15 @@
<script lang="ts">
import Vue from 'vue';
import {Component} from 'vue-property-decorator';
import store from '@/store';
@Component
@Component({
computed:{
labelList(){
return store.state.labelList
}
}
})
export default class Choice extends Vue {
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/Account/Note.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<template>
<label>
{{value}}
<span>备注</span>
<input type="text" placeholder="在这里添加备注">
<input type="text" v-model="value"
placeholder="在这里添加备注">
</label>
</template>

Expand All @@ -11,7 +13,7 @@
@Component
export default class Note extends Vue {
value = '';
}
</script>

Expand Down
13 changes: 10 additions & 3 deletions src/components/Account/Show.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
<template>
<div class="show">
<div class="text">金额</div>
<div class="number">100.12</div>
<div class="number">{{output}}</div>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import {Component} from 'vue-property-decorator';
import personStore from '@/store/personStore'
@Component
@Component({
// todo
computed:{
output(){
return personStore.output;
}
}
})
export default class Show extends Vue {
}
</script>

Expand Down
42 changes: 28 additions & 14 deletions src/components/Account/Write.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
<template>
<div class="buttons">
<button>1</button>
<button>2</button>
<button>3</button>
<button>删除</button>
<button>4</button>
<button>5</button>
<button>6</button>
<button class="clear">清空</button>
<button>7</button>
<button>8</button>
<button>9</button>
<button @click="inputContent">1</button>
<button @click="inputContent">2</button>
<button @click="inputContent">3</button>
<button @click="remove">删除</button>
<button @click="inputContent">4</button>
<button @click="inputContent">5</button>
<button @click="inputContent">6</button>
<button @click="empty">清空</button>
<button @click="inputContent">7</button>
<button @click="inputContent">8</button>
<button @click="inputContent">9</button>
<button class="ok">确认</button>
<button class="zero">0</button>
<button>.</button>
<button @click="inputContent" class="zero">0</button>
<button @click="inputContent">.</button>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import {Component} from 'vue-property-decorator';
import personStore from '@/store/personStore';
@Component
export default class Write extends Vue {
remove(){
// todo
personStore.remove();
console.log(personStore.output)
}
empty(){
personStore.empty();
console.log(personStore.output)
}
inputContent(event: MouseEvent){
personStore.inputContent(event);
console.log(personStore.output)
}
}
</script>

Expand Down
17 changes: 12 additions & 5 deletions src/components/Type.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
<template>
<ul>
<li class="selected">支出</li>
<li>收入</li>
<li :class="{selected: type==='+'}" @click="selectA">支出</li>
<li :class="{selected: type==='-'}" @click="selectB">收入</li>
</ul>
</template>

<script lang="ts">
import Vue from 'vue';
import {Component} from 'vue-property-decorator';
@Component
export default class Top2 extends Vue {
export default class Type extends Vue {
typeList=['+','-'];
type='+';
selectA(){
this.type=this.typeList[0]
}
selectB(){
this.type=this.typeList[1]
}
}
</script>

Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import store from './store';
import Nav from '@/components/Nav.vue';
import Top from '@/components/Top.vue';
import Layout from '@/components/Layout.vue';
import personStore from '@/store/personStore';


Vue.config.productionTip = false;
Vue.component('Top',Top);
Expand Down
28 changes: 18 additions & 10 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import Vue from 'vue'
import Vuex from 'vuex'
import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex)
type LabelList = {
labelList: string[];
}

export default new Vuex.Store({
state: {
Vue.use(Vuex);
const store = new Vuex.Store({
state:{
labelList:['默认','衣','食','住','行']
},
mutations: {
},
actions: {
},
modules: {
addLabel(state){
state.labelList.push('彩票')
}
}
})
});

store.commit('addLabel');

export default store

30 changes: 30 additions & 0 deletions src/store/personStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const store = {
output: '124',
fetchOutput() {
return this.output;
},
remove(){
if(this.output.length<=1){
this.output = '0';
}else{
this.output = this.output.slice(0,-1)
}
},
empty(){
this.output = '0';
},
inputContent(event: MouseEvent){
const input = (event.target as HTMLButtonElement).textContent as string;
if(this.output.length<=16){
if(this.output ==='0' && input !=='.'){
this.output = input;
}else{
if(this.output.indexOf('.')>=0 && input ==='.'){
return
}
this.output += input;
}
}
}
};
export default store
12 changes: 8 additions & 4 deletions src/views/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Type/>
<Choice/>
<Note/>
<Show/>
<Show @ok="onOutputChange"/>
<Write/>
</Layout>
</template>
Expand All @@ -17,11 +17,15 @@
import Write from '@/components/Account/Write.vue';
import Show from '@/components/Account/Show.vue';
@Component({
components: {Show, Write, Note, Choice, Type}
})
components: {Show, Write, Note, Choice, Type},
},)
export default class Account extends Vue {
output='0';
onOutputChange(){
console.log("检测到 output 变化啦")
}
}
</script>

Expand Down

0 comments on commit 3c646d0

Please sign in to comment.