inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

Vue.js - Django 연동 웹 프로그래밍

주요 사항 정리 하기

응용해서 만들어봤는데 신기한걸 발견했습니다.

161

김동혁

작성한 질문수 48

0


<body>
<div id='app'>

<h1>소모품대장 계산 도우미</h1>

<div class="inputBox">
<small>현재 재고는 <b>{{ inStock }}</b>입니다.</small>
<input class="use" type="text" placeholder="불출량 입력하세요" v-model="use">
<button v-on:click="usingInStock(use)" v-on:keyup.enter="usingInStock(use)">사용</button>
</div>
<div class="inputBox">
<small>추가 입고분이 있다면 입력해주세요.</small>
<input class="store" type="text" placeholder="입고량 입력하세요" v-model="store">
<button v-on:click="storingInStock(store)" v-on:keyup.enter="storingInStock(store)">사용</button>
</div>

<ul class="todoList">
<li v-for="(record, index) in records">
<span>{{index}} :: 날짜는 : {{record.Today_date}} - 재고는 : {{ record.currunt_data }} </span>
</li>
</ul>

</div>
<script src="https://unpkg.com/vue@2.6.10/dist/vue.js"></script>

<script>
function getRandomIntInclusive(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var vm = new Vue({
el: '#app',
data: {
inStock: '1581',
use: '',
store: '',
str1: '',
tempDate: new Date(2018, 0, 1),
fistDate: '',
records: [
{Today_date: '', currunt_data: ''}
],
},
methods: {
usingInStock: function(use){
this.inStock -= this.use
var d = new Date();
var week = new Array('일', '월', '화', '수', '목', '금', '토');
// this.tempDate.setDate(this.tempDate.getDate() + getRandomIntInclusive(6, 7))
this.tempDate.setDate(this.tempDate.getDate() + 7)
// this.str1 = week[this.tempDate.getDay()]
// console.log("하하하", this.str1, d.getDate(), d.getDay())
this.records.unshift({Today_date:this.tempDate.toLocaleString('ko-KR', {year: "numeric", month:"2-digit", day:"2-digit", weekday: 'short' }), currunt_data: this.inStock})
 
},
storingInStock: function(store){
this.store = parseInt(this.store)
this.inStock = parseInt(this.inStock)
this.inStock += this.store
}
}
}
)
</script>

</body>

위와 같이 코드를 만들어봤는데요

this.inStock에서 -= 변수 하면 instock이 int형으로 잘 반응합니다. *= 도 잘 반응합니다.

근데 왜 +=하면 str + str로 되버려서 

제가 따로 저렇게 형변환을 해줘야됩니다. 

왜이런지 궁금합니다.

vuejs django

답변 1

1

김석훈

자바스크립트 문법에서, 숫자형과 문자열의 연산은 다음과 같습니다.

a + b 는, String Concatenation 을 고려하여, 숫자형을 문자형으로 변환해서 처리 합니다.

그 외, a - b, a * b, a / b 는, 문자형을 숫자형으로 변환해서 처리합니다.

좀 복잡한 면이 있으므로, 자바스크립트 연산자 문법을 한번 보시기 바랍니다.

들여쓰기 단축키가 어떻게 되나요?

0

253

1

mixin 에러가 나서 실행이 안되요.

0

420

4

화면 에러화면이 자꾸 뜨네요..

0

418

4

todo_form.html 하단에 todo_List.html의 리스트가 오게 하고 싶습니다.

0

353

1

bootodo.html에서 Vue 코드가 적용되지 않습니다.

0

577

1

cdn vue버전

3

720

2

bootstrap 팝업창 만들기 단원에서 질문있습니다.

0

921

3

MultipleObjectMixin get 메소드 상속

0

253

1

Vue에서 파일 업로드시

0

718

1

vue django 연동 질문

0

501

1

장고 프론트엔드 백엔드 분리 관련 질문입니다 !

0

491

1

home화면에서 이미지가 안보입니다.

0

293

2

이 강의와 새로 만드신 강의의 차이점을 알고 싶습니다.

0

301

1

좋은 강의 감사합니다.

0

249

1

staticfiles가 static으로 바뀌었습니다.

0

278

1

장고 3.1에서 다음과 같이 바뀌었습니다.

0

293

2

Vuejs 와 Reactjs의 차이

0

356

1

vue js 오픈소스 연동

0

495

2

createView에서 success_url

0

252

1

강의자료 HtmlTodo.zip 파일 구글드라이브에서 바이러스로 인식해서 다운로드 안됩니다.

1

269

2

object에 왜 todo 컬럼이 추가되는지?

0

209

2

django_only 실습중 에러 제보

0

279

3

BaseListView

1

276

1

todo_confirm_delete.html

1

345

1