帮我优化下下面代码,我要更新status。监听数据变化,更新status. <template> <div :class="['node', status]"> <img :src="image.logo" alt="logo" @click="setClick"/> <span class="label">{{ label }}</span> <span class="status"> <img v-if="status === 'success'" :src="image.success" alt="success" /> <img v-if="status === 'failed'" :src="image.failed" alt="failed" /> <img v-if="status === 'running'" :src="image.running" alt="running" /> </span> </div> </template> <script setup> import { inject } from 'vue' import logoSet from '@/assets/img/set.png' import statusSuccess from '@/assets/img/success.png' import statusFailed from '@/assets/img/failed.png' import statusRunning from '@/assets/img/running.png' // 注入依赖 const getNode = inject('getNode'); const data = getNode()?.getData() || {} const { label, status = 'default' } = data //监听data变化,更新状态 getNode.on('change:data', ({ data }) => { const { status } = data status = status }) const image = { logo: logoSet, success: statusSuccess, failed: statusFailed, running: statusRunning } const setClick=()=>{ // alert('111') } </script>
理解问题帮我优化下下面代码,我要更新status。监听数据变化,更新status. <template> <div :class="['node', status]"> <img :src="image.logo" alt="logo" @click="setClick"/> <span class="label">{{ label }}</span> <span class="status"> <img v-if="status === 'success'" :src="image.success" alt="success" /> <img v-if="status === 'failed'" :src="image.failed" alt="failed" /> <img v-if="status === 'running'" :src="image.running" alt="running" /> </span> </div> </template> <script setup> import { inject } from 'vue' import logoSet from '@/assets/img/set.png' import statusSuccess from '@/assets/img/success.png' import statusFailed from '@/assets/img/failed.png' import statusRunning from '@/assets/img/running.png' // 注入依赖 const getNode = inject('getNode'); const data = getNode()?.getData() || {} const { label, status = 'default' } = data //监听data变化,更新状态 getNode.on('change:data', ({ data }) => { const { status } = data status = status }) const image = { logo: logoSet, success: statusSuccess, failed: statusFailed, running: statusRunning } const setClick=()=>{ // alert('111') } </script>
已完成理解「帮我优化下下面代码,我要更新status。监听数据变化,更新status. <template> <div :class="['node', status]"> <img :src="image.logo" alt="logo" @click="setClick"/> <span class="label">{{ label }}</span> <span class="status"> <img v-if="status === 'success'" :src="image.success" alt="success" /> <img v-if="status === 'failed'" :src="image.failed" alt="failed" /> <img v-if="status === 'running'" :src="image.running" alt="running" /> </span> </div> </template> <script setup> import { inject } from 'vue' import logoSet from '@/assets/img/set.png' import statusSuccess from '@/assets/img/success.png' import statusFailed from '@/assets/img/failed.png' import statusRunning from '@/assets/img/running.png' // 注入依赖 const getNode = inject('getNode'); const data = getNode()?.getData() || {} const { label, status = 'default' } = data //监听data变化,更新状态 getNode.on('change:data', ({ data }) => { const { status } = data status = status }) const image = { logo: logoSet, success: statusSuccess, failed: statusFailed, running: statusRunning } const setClick=()=>{ // alert('111') } </script>」
展开阅读网页