const options = {
root: null,
rootMargin: '0px',
threshold: 1.0
}
const svg = document.querySelector('svg')
const animation = document.getElementById('animate')
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
animation.beginElement()
svg.style.display = 'block'
}
})
}, options)
observer.observe(document.querySelector('#anim1'))
<animate id="animate" .../>
const createTimerAnimator = () => {
let intervalId
return (time) => {
if (intervalId) clearInterval(intervalId)
const visibleResult = () => {
const formatter = Intl.NumberFormat(undefined, {
minimumIntegerDigits: 2
})
const hours = formatter.format(Math.floor(time / 60 / 60))
const minutes = formatter.format(Math.floor(time / 60) - (hours * 60))
const seconds = formatter.format(time % 60)
timerEl.textContent = `${hours} : ${minutes} : ${seconds}`
}
visibleResult()
intervalId = setInterval(() => {
if (time > 0) {
visibleResult(time--)
} else {
clearInterval(intervalId)
}
}, 1000)
}
}
child.value.publicMethod()
export default {
expose: ['publicData', 'publicMethod'],
data() {
return {
publicData: 'foo',
privateData: 'bar'
}
},
methods: {
publicMethod() {
/* ... */
},
privateMethod() {
/* ... */
}
}
}
<script>
import Child from './Child.vue'
export default {
components: {
Child
},
mounted() {
}
}
</script>
<template>
<Child ref="child" />
</template>
<div>
<slot :text="greetingMessage" :count="1"></slot>
</div>
<MyComponent v-slot="slotProps">
{{ slotProps.text }} {{ slotProps.count }}
</MyComponent>
<template>
<div>
<v-child ref="refChild" />
<button @click="getDataFromChild">Call child function</button>
</div>
</template>
<script setup>
import VChild from './VChild.vue'
import { ref } from 'vue'
const refChild = ref()
function getDataFromChild() {
if (refChild.value) {
refChild.value.childFunction()
}
}
</script>
<template>
<div>{{ msgHello }}</div>
</template>
<script setup>
import { ref } from 'vue'
const msgHello = ref('Try to click on')
function childFunction() {
msgHello.value = 'childFunction called!'
}
defineExpose({childFunction})
</script>
const banned = await mongo.models.chatsusers.find({ join_chat: Number(message.chatId), banned: true })
if (banned.length) {
let output = ''
for (a in banned)
output += `[id${banned[a].vkid}|${banned[a].name}]\n`
return message.send(` Вот список заблокированных:\n\n${output}`)
}
return message.send(` В списке забаненных никого нет.`)
10+10
let r = 10
let l = 10
let operator = '+'
...
...
let result
if (operator === '+') {
result = r + l
}
let x = 10
let y = "+"
let w = 10
eval(x + y + w) // 20
<span v-for="i in 20" :key="i" ref="spans">{{ i }}</span>
const spans = ref()
onMounted(() => {
console.log(spans.value)
})
expose
, затем через ref
ими пользоваться const allChildren = document.querySelectorAll('.animate-text')
let index = 0
allChildren.forEach(elm => {
for (let i = 0; i < elm.children.length; i++) {
const child = elm.children[i]
child.classList.remove('text-in', 'text-out')
}
elm.children[index].classList.add('text-in')
})