Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3е занятие все задачи #3

Merged
merged 13 commits into from
Dec 24, 2024
Merged
15 changes: 11 additions & 4 deletions 02-basics-2/10-counter/CounterApp.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
import { defineComponent } from 'vue'
import { defineComponent, ref } from 'vue'

export default defineComponent({
name: 'CounterApp',

setup() {},
setup() {
const counter = ref(0);

return {counter}
},

template: `
<div class="counter">
<button
class="button button--secondary"
type="button"
aria-label="Decrement"
disabled
:disabled="counter <= 0"
@click="counter--"
>➖</button>

<span class="count" data-testid="count">0</span>
<span class="count" data-testid="count">{{ counter }}</span>

<button
class="button button--secondary"
type="button"
aria-label="Increment"
:disabled="counter >= 5"
@click="counter++"
>➕</button>
</div>
`,
Expand Down
58 changes: 26 additions & 32 deletions 02-basics-2/20-broken-map/MapApp.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
import { defineComponent, ref, watch } from 'vue'
import { defineComponent, ref } from 'vue'

export default defineComponent({
name: 'MapApp',
name: 'MapApp',

setup() {
// Реактивные переменные для хранения координат метки
let x = ref(0)
let y = ref(0)
setup() {
// Реактивные переменные для хранения координат метки
let x = ref(0)
let y = ref(0)

/**
* Обработчик клика по карте для установки координат метки
* @param {MouseEvent} event
*/
function handleClick(event) {
x = event.offsetX
y = event.offsetY
}
/**
* Обработчик клика по карте для установки координат метки
* @param {MouseEvent} event
*/
function handleClick(event) {
x.value = event.offsetX
y.value = event.offsetY
}

// Следим за X и Y для установки нового положения
watch([x, y], () => {
// Находим метку и изменяем её положение
const map = document.querySelector('.pin')
map.style.left = `${x}px`
map.style.top = `${y}px`
})
return {
x,
y,
handleClick,
}
},

return {
handleClick,
}
},

template: `
<div class="map" @click="handleClick">
<img class="map-image" src="./map.png" alt="Map" draggable="false" />
<span class="pin">📍</span>
</div>
`,
template: `
<div class="map" @click="handleClick">
<img class="map-image" src="./map.png" alt="Map" draggable="false"/>
<span class="pin" :style="{left: x+'px', top: y+'px'}">📍</span>
</div>
`,
})
61 changes: 44 additions & 17 deletions 02-basics-2/30-calculator/CalculatorApp.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,53 @@
import { defineComponent } from 'vue'
import {defineComponent, ref, computed} from 'vue'

export default defineComponent({
name: 'CalculatorApp',
name: 'CalculatorApp',

setup() {},
setup() {
const value1 = ref(0);
const value2 = ref(0);
const operator = ref('sum');

template: `
<div class="calculator">
<input type="number" aria-label="First operand" />
const result = computed(() => {
switch (operator.value) {
case 'sum':
return value1.value + value2.value
case 'subtract':
return value1.value - value2.value
case 'multiply':
return value1.value * value2.value
case 'divide':
return value1.value / value2.value
default:
return value1.value + value2.value;
}
})

<div class="calculator__operators">
<label><input type="radio" name="operator" value="sum"/>➕</label>
<label><input type="radio" name="operator" value="subtract"/>➖</label>
<label><input type="radio" name="operator" value="multiply"/>✖</label>
<label><input type="radio" name="operator" value="divide"/>➗</label>
</div>
return {
value1,
value2,
operator,
result
}

<input type="number" aria-label="Second operand" />
},

<div>=</div>
template: `
<div class="calculator">
<input v-model="value1" type="number" aria-label="First operand"/>

<output>0</output>
</div>
`,
<div class="calculator__operators">
<label><input v-model="operator" type="radio" name="operator" value="sum"/>➕</label>
<label><input v-model="operator" type="radio" name="operator" value="subtract"/>➖</label>
<label><input v-model="operator" type="radio" name="operator" value="multiply"/>✖</label>
<label><input v-model="operator" type="radio" name="operator" value="divide"/>➗</label>
</div>

<input v-model="value2" type="number" aria-label="Second operand"/>

<div>=</div>

<output>{{ result }}</output>
</div>
`,
})
100 changes: 57 additions & 43 deletions 02-basics-2/40-marked-emails/MarkedEmailsApp.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,66 @@
import { computed, defineComponent, ref } from 'vue'
import {computed, defineComponent, ref} from 'vue'

// Значения взяты из https://jsonplaceholder.typicode.com/comments
export const emails = [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
]

export default defineComponent({
name: 'MarkedEmailsApp',
name: 'MarkedEmailsApp',

setup() {},
setup() {
const search = ref('');

template: `
<div>
<div class="form-group">
<input type="search" aria-label="Search" />
</div>
<ul aria-label="Emails">
<li>
[email protected]
</li>
<li class="marked">
[email protected]
</li>
</ul>
</div>
`,
const filteredEmails = computed(() => {
const arr = [];
emails.forEach(email => arr.push({emailValue: email, isFlagged: search.value && email.toLowerCase().includes(search.value.toLowerCase())}));
return arr;
})
Comment on lines +39 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь хорошо подойдёт метод массива map


return {
search,
filteredEmails
}
},

template: `
<div>
<div class="form-group">
<input v-model="search" type="search" aria-label="Search"/>
</div>
<ul aria-label="Emails">
<li
v-for="(email, index) in filteredEmails"
:key="index"
:class="{'marked': email.isFlagged}"
>
{{ email.emailValue }}
</li>
</ul>
</div>
`,
})
Loading
Loading