Demo1.vue 825 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <div>
  3. <h2>Demo1</h2>
  4. <p>
  5. {{ tips }}
  6. </p>
  7. <button @click="changeTips">修改</button>
  8. </div>
  9. </template>
  10. <script lang="ts" setup name="hi">
  11. /**
  12. * setup 不支持this
  13. * ref 基本数据类型
  14. * 声明字段 自带value
  15. * 修改需要.value
  16. */
  17. import {ref} from 'vue';
  18. let tips = ref('今天星期日');
  19. console.log(tips);
  20. function changeTips() {
  21. // this.tips = 'haha';
  22. tips.value = '哈哈';
  23. }
  24. </script>
  25. <!-- <script>
  26. export default {
  27. name:"hi"
  28. }
  29. </script> -->
  30. <!-- <script>
  31. import { ref } from "vue";
  32. export default {
  33. name:"hello",
  34. setup() {
  35. let tips = ref("哈哈");
  36. function changeTips() {
  37. // this.tips = 'haha';
  38. tips.value = "你好";
  39. }
  40. return {
  41. tips,changeTips
  42. };
  43. },
  44. };
  45. </script> -->
  46. <style lang="scss" scoped>
  47. </style>