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>
<script setup>
import { computed } from 'vue'
const ifShow = computed(() => {
return (isShow) => isShow === 'some day'
})
</script>
<template>
<span v-show="ifShow('some day')">Hi!</span>
</template>
export default {
data() {
return {}
},
computed: {
ifShow() {
return (isShow) => isShow === 'some day'
}
}
}
div {
display: flex;
}
.container {
position: relative;
justify-content: space-between;
flex-direction: row;
width: 100%;
}
.center {
width: 100%;
justify-content: center;
position: absolute;
}
<div class="container">
<div>left</div>
<div class="center">
<div>
center block
</div>
</div>
<div>right</div>
</div>
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(` В списке забаненных никого нет.`)
getCurrentInstance
import { getCurrentInstance } from 'vue'
export function useI18n() {
const instance = getCurrentInstance()
if (!instance) return (localeString: string) => localeString // вернем строку обратно
return instance.appContext.config.globalProperties.$t
}
<script setup lang="ts">
import useI18n from '@/utils/useI18n'
const t = useI18n()
</script>
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
<div class="info__item" style="margin-top: -2em">
</div>