vue-temp-var

A Vue component for defining temporary variables in the template with type inference.
7,724 7
Install
npm install vue-temp-var
Latest Version:2.0.1
Vue:3
License:MIT
Last Updated:Aug 3, 2026
Links: GitHub  ·  npm
Maintainer: deviltea

vue-temp-var

A Vue component for defining temporary variables in the template with type inference.

Checkout the discussion of https://github.com/vuejs/rfcs/discussions/505

Vue 3.3.0+ is required.

Install

npm install vue-temp-var

Usage

<script setup lang="ts">
import TempVar from 'vue-temp-var'

function getRandomNumber() {
	return Math.random()
}
</script>

<template>
	<div
		v-for="i in 10"
		:key="`random-${i}`"
	>
		<!-- cause the return value would be random, we should store it somewhere. -->
		<!-- bind a prop 'define' to 'TempVar'. Because it is a prop, it would still be reactive. -->
		<!-- destruct from slot: defined, the type would be kept -->
		<TempVar
			v-slot="{ randomNum }"
			:define="{ randomNum: getRandomNumber() }"
		>
			<span>"{{ randomNum }}"</span>
			<span v-if="randomNum > 0.5"> is larger than 0.5</span>
			<span v-else> is smaller than 0.5</span>
		</TempVar>
	</div>
</template>

License

MIT

Related Packages

vue

The progressive JavaScript framework for building modern web UI.

588,019,132 54,801
vue
@vueuse/shared
372,738,348 22,398
@vueuse/core

Collection of essential Vue Composition Utilities

367,188,523 22,398
@vitejs/plugin-vue

The official plugin for Vue SFC support in Vite.

333,357,380 686
eslint-plugin-vue

Official ESLint plugin for Vue.js

266,364,830 4,591

Version History

Version Released Vue License
2.0.1 >=3.3.0 MIT
2.0.0 >=3.3.0 MIT
1.0.0 >=3.3.0 MIT
0.0.2 >=3.3.0 MIT
0.0.1 >=3.3.0 MIT