Vue-cli3 is used and typescript, is enabled. Please tell me how to declare the type to the value in data.

<script lang="ts">
import Vue from "vue"
import HelloWorld from "@/components/HelloWorld.vue"

export default Vue.extend({
    components: { HelloWorld },
    data () {
        return {
            bb: "123"
        }
    },
    watch: {
        bb (val: String) {
            console.log(val)
        }
    },
    props: {
        propA: Number
    },
    methods: {
        haha (a: String) {
            console.log(a)
        }
    },
    created () {
    }
})
</script>

at present, everything except data works normally, but there is no clue as to how the content in data declares the type. The official document seems to only give the writing method of "class-based Vue component". However, in order to maintain the consistency with the old project, we do not want to use this method at present.

clipboard.png


set the interface of the return value of the data function

data(): iData{
    return(
        a: ''
    
}
interface iData{
    a: string
}

check out vue-class-component


you can write
`

data(){
    const dataSource: ListItem[] = []
    return {
        dataSource
    }
}

`


bb: string = 'abc'

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b332ec-2abba.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b332ec-2abba.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?