As a user of vue.js,i use jsx to write code. There are a lot of .value
in my code.
#9250
Replies: 4 comments 1 reply
-
You can use like this: export default {
setup() {
const msg = ref('')
watch(msg, (val) => {
console.log(val)
})
const data = reactive({
msg,
})
return () => (
<div>
<h2>{ data.msg }</h2>
<input value={ data.msg } onInput={ (e) => data.msg = e.target.value } />
</div>
);
},
}; If the And there is a simple Vue JSX playground. |
Beta Was this translation helpful? Give feedback.
-
I understand that you don’t want to use the |
Beta Was this translation helpful? Give feedback.
-
In fact, you can also write like this: import { defineComponent, getCurrentInstance } from 'vue'
export default defineComponent({
name: 'App',
setup() {
const instance = getCurrentInstance()
let msg = 'Hello World'
function setState(cb: () => void) {
cb()
instance?.proxy?.$forceUpdate()
}
return () => {
return (
<div>
<h1>{msg}</h1>
<button onClick={() => setState(() => (msg = 'Hello Vue 3'))}>
Click
</button>
</div>
)
}
}
}) Don't mind if you are naughty😄 |
Beta Was this translation helpful? Give feedback.
-
Maybe You can try https://vue-macros.sxzz.moe/features/jsx-directive.html it |
Beta Was this translation helpful? Give feedback.
-
As a user of vue.js,i use jsx to write code. There are a lot of
.value
in my code.For example:
When I have a variable, I need to write a
.value
in the code.I thought of a solution. This solution is to check whether it is
ref
when renderingnode
. If it isref
, take out the value ofref
as the rendering result.For example:
Beta Was this translation helpful? Give feedback.
All reactions